2562. Find the Array Concatenation Value Easy

@problem@discussion
#Array#Two Pointers#Simulation



1/**
2 * [2562] Find the Array Concatenation Value
3 *
4 * You are given a 0-indexed integer array nums.
5 * The concatenation of two numbers is the number formed by concatenating their numerals.
6 * 
7 * 	For example, the concatenation of 15, 49 is 1549.
8 * 
9 * The concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:
10 * 
11 * 	If there exists more than one number in nums, pick the first element and last element in nums respectively and add the value of their concatenation to the concatenation value of nums, then delete the first and last element from nums.
12 * 	If one element exists, add its value to the concatenation value of nums, then delete it.
13 * 
14 * Return the concatenation value of the nums.
15 *  
16 * <strong class="example">Example 1:
17 * 
18 * Input: nums = [7,52,2,4]
19 * Output: 596
20 * Explanation: Before performing any operation, nums is [7,52,2,4] and concatenation value is 0.
21 *  - In the first operation:
22 * We pick the first element, 7, and the last element, 4.
23 * Their concatenation is 74, and we add it to the concatenation value, so it becomes equal to 74.
24 * Then we delete them from nums, so nums becomes equal to [52,2].
25 *  - In the second operation:
26 * We pick the first element, 52, and the last element, 2.
27 * Their concatenation is 522, and we add it to the concatenation value, so it becomes equal to 596.
28 * Then we delete them from the nums, so nums becomes empty.
29 * Since the concatenation value is 596 so the answer is 596.
30 * 
31 * <strong class="example">Example 2:
32 * 
33 * Input: nums = [5,14,13,8,12]
34 * Output: 673
35 * Explanation: Before performing any operation, nums is [5,14,13,8,12] and concatenation value is 0.
36 *  - In the first operation:
37 * We pick the first element, 5, and the last element, 12.
38 * Their concatenation is 512, and we add it to the concatenation value, so it becomes equal to 512.
39 * Then we delete them from the nums, so nums becomes equal to [14,13,8].
40 *  - In the second operation:
41 * We pick the first element, 14, and the last element, 8.
42 * Their concatenation is 148, and we add it to the concatenation value, so it becomes equal to 660.
43 * Then we delete them from the nums, so nums becomes equal to [13].
44 *  - In the third operation:
45 * nums has only one element, so we pick 13 and add it to the concatenation value, so it becomes equal to 673.
46 * Then we delete it from nums, so nums become empty.
47 * Since the concatenation value is 673 so the answer is 673.
48 * 
49 *  
50 * Constraints:
51 * 
52 * 	1 <= nums.length <= 1000
53 * 	1 <= nums[i] <= 10^4
54 * 
55 *  
56 * <style type="text/css">.spoilerbutton {display:block; border:dashed; padding: 0px 0px; margin:10px 0px; font-size:150%; font-weight: bold; color:#000000; background-color:cyan; outline:0; 
57 * }
58 * .spoiler {overflow:hidden;}
59 * .spoiler > div {-webkit-transition: all 0s ease;-moz-transition: margin 0s ease;-o-transition: all 0s ease;transition: margin 0s ease;}
60 * .spoilerbutton[value="Show Message"] + .spoiler > div {margin-top:-500%;}
61 * .spoilerbutton[value="Hide Message"] + .spoiler {padding:5px;}
62 * </style>
63 * 
64 */
65pub struct Solution {}
66
67// problem: https://leetcode.com/problems/find-the-array-concatenation-value/
68// discuss: https://leetcode.com/problems/find-the-array-concatenation-value/discuss/?currentPage=1&orderBy=most_votes&query=
69
70// submission codes start here
71
72impl Solution {
73    pub fn find_the_array_conc_val(nums: Vec<i32>) -> i64 {
74        
75    }
76}
77
78// submission codes end
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn test_2562() {
86    }
87}
88


Back
© 2025 bowen.ge All Rights Reserved.