1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution { public long findTheArrayConcVal(int[] nums) { long concVal = 0;
int i = -1, j = nums.length; while (++i < --j) { int leftNum = nums[i], rightNum = nums[j]; concVal += (long) leftNum * getBase(rightNum) + rightNum; }
if (i == j) { concVal += nums[i]; }
return concVal; }
private int getBase(int num) { int product = 1; while (num > 0) { num /= 10; product *= 10; }
return product; } }
|
References
2562. Find the Array Concatenation Value