Find the Array Concatenation Value
You are given a 0-indexed integer array nums.
The concatenation of two numbers is the number formed by concatenating their numerals.
- For example, the concatenation of
15and49is1549.
The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:
- If
numshas a size greater than one, add the value of the concatenation of the first and the last element to the concatenation value ofnums, and remove those two elements fromnums. - If only one element exists in
nums, add its value to the concatenation value ofnums, then remove it.
Return the concatenation value of nums.
Example 1
Input
nums = [7,52,2,4]Output
596The operations add the concatenations 74 and 522, giving a total concatenation value of 596.
Example 2
Input
nums = [5,14,13,8,12]Output
673The operations add 512, 148, and the remaining element 13, giving a total concatenation value of 673.
Constraints
- 1 <= nums.length <= 1000
- 1 <= nums[i] <= 10^4