2562. 找出数组的串联值
题目
题解
- 直接使用双指针,依次拼接
- 如果指针结束指向同一个数,则再加上该数
class Solution {
public long findTheArrayConcVal(int[] nums) {
int left = 0;
int right = nums.length - 1;
long res = 0;
while (right > left) {
int lv = nums[left];
int rv = nums[right];
while (rv > 0) {
rv = rv / 10;
lv = lv * 10;
}
res = res + lv + nums[right];
left++;
right--;
}
if (left == right) {
return res + nums[left];
}
return res;
}
}