下面是用 Java 实现的代码:
public int arrayConnection(int[] nums) {
int result = 0;
while (nums.length > 0) {
if (nums.length == 1) {
result += nums[0];
nums = new int[0];
} else {
result += nums[0] + nums[nums.length - 1];
nums = Ar