File tree Expand file tree Collapse file tree 5 files changed +205
-1
lines changed
solution/2500-2599/2562.Find the Array Concatenation Value Expand file tree Collapse file tree 5 files changed +205
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,16 @@ nums 只有一个元素,所以我们选中 13 并将其加到串联值上,
82
82
<!-- 这里可写当前语言的特殊实现逻辑 -->
83
83
84
84
``` python
85
-
85
+ class Solution :
86
+ def findTheArrayConcVal (self , nums : List[int ]) -> int :
87
+ ans = 0
88
+ i, j = 0 , len (nums) - 1
89
+ while i < j:
90
+ ans += int (str (nums[i]) + str (nums[j]))
91
+ i, j = i + 1 , j - 1
92
+ if i == j:
93
+ ans += nums[i]
94
+ return ans
86
95
```
87
96
88
97
### ** Java**
@@ -140,6 +149,76 @@ func findTheArrayConcVal(nums []int) (ans int64) {
140
149
}
141
150
```
142
151
152
+ ### ** TypeScript**
153
+
154
+ ``` ts
155
+ function findTheArrayConcVal(nums : number []): number {
156
+ const n = nums .length ;
157
+ let ans = 0 ;
158
+ let i = 0 ;
159
+ let j = n - 1 ;
160
+ while (i < j ) {
161
+ ans += Number (` ${nums [i ]}${nums [j ]} ` );
162
+ i ++ ;
163
+ j -- ;
164
+ }
165
+ if (i === j ) {
166
+ ans += nums [i ];
167
+ }
168
+ return ans ;
169
+ }
170
+ ```
171
+
172
+ ### ** Rust**
173
+
174
+ ``` rust
175
+ impl Solution {
176
+ pub fn find_the_array_conc_val (nums : Vec <i32 >) -> i64 {
177
+ let n = nums . len ();
178
+ let mut ans = 0 ;
179
+ let mut i = 0 ;
180
+ let mut j = n - 1 ;
181
+ while i < j {
182
+ ans += format! (" {}{}" , nums [i ], nums [j ]). parse :: <i64 >(). unwrap ();
183
+ i += 1 ;
184
+ j -= 1 ;
185
+ }
186
+ if i == j {
187
+ ans += nums [i ] as i64 ;
188
+ }
189
+ ans
190
+ }
191
+ }
192
+ ```
193
+
194
+ ### ** C**
195
+
196
+ ``` c
197
+ int getLen (int num) {
198
+ int res = 0;
199
+ while (num) {
200
+ num /= 10;
201
+ res++;
202
+ }
203
+ return res;
204
+ }
205
+
206
+ long long findTheArrayConcVal(int * nums, int numsSize) {
207
+ long long ans = 0;
208
+ int i = 0;
209
+ int j = numsSize - 1;
210
+ while (i < j) {
211
+ ans += nums[ i] * pow(10, getLen(nums[ j] )) + nums[ j] ;
212
+ i++;
213
+ j--;
214
+ }
215
+ if (i == j) {
216
+ ans += nums[ i] ;
217
+ }
218
+ return ans;
219
+ }
220
+ ```
221
+
143
222
### **...**
144
223
145
224
```
Original file line number Diff line number Diff line change @@ -148,6 +148,76 @@ func findTheArrayConcVal(nums []int) (ans int64) {
148
148
}
149
149
```
150
150
151
+ ### ** TypeScript**
152
+
153
+ ``` ts
154
+ function findTheArrayConcVal(nums : number []): number {
155
+ const n = nums .length ;
156
+ let ans = 0 ;
157
+ let i = 0 ;
158
+ let j = n - 1 ;
159
+ while (i < j ) {
160
+ ans += Number (` ${nums [i ]}${nums [j ]} ` );
161
+ i ++ ;
162
+ j -- ;
163
+ }
164
+ if (i === j ) {
165
+ ans += nums [i ];
166
+ }
167
+ return ans ;
168
+ }
169
+ ```
170
+
171
+ ### ** Rust**
172
+
173
+ ``` rust
174
+ impl Solution {
175
+ pub fn find_the_array_conc_val (nums : Vec <i32 >) -> i64 {
176
+ let n = nums . len ();
177
+ let mut ans = 0 ;
178
+ let mut i = 0 ;
179
+ let mut j = n - 1 ;
180
+ while i < j {
181
+ ans += format! (" {}{}" , nums [i ], nums [j ]). parse :: <i64 >(). unwrap ();
182
+ i += 1 ;
183
+ j -= 1 ;
184
+ }
185
+ if i == j {
186
+ ans += nums [i ] as i64 ;
187
+ }
188
+ ans
189
+ }
190
+ }
191
+ ```
192
+
193
+ ### ** C**
194
+
195
+ ``` c
196
+ int getLen (int num) {
197
+ int res = 0;
198
+ while (num) {
199
+ num /= 10;
200
+ res++;
201
+ }
202
+ return res;
203
+ }
204
+
205
+ long long findTheArrayConcVal(int * nums, int numsSize) {
206
+ long long ans = 0;
207
+ int i = 0;
208
+ int j = numsSize - 1;
209
+ while (i < j) {
210
+ ans += nums[ i] * pow(10, getLen(nums[ j] )) + nums[ j] ;
211
+ i++;
212
+ j--;
213
+ }
214
+ if (i == j) {
215
+ ans += nums[ i] ;
216
+ }
217
+ return ans;
218
+ }
219
+ ```
220
+
151
221
### **...**
152
222
153
223
```
Original file line number Diff line number Diff line change
1
+ int getLen (int num ) {
2
+ int res = 0 ;
3
+ while (num ) {
4
+ num /= 10 ;
5
+ res ++ ;
6
+ }
7
+ return res ;
8
+ }
9
+
10
+ long long findTheArrayConcVal (int * nums , int numsSize ) {
11
+ long long ans = 0 ;
12
+ int i = 0 ;
13
+ int j = numsSize - 1 ;
14
+ while (i < j ) {
15
+ ans += nums [i ] * pow (10 , getLen (nums [j ])) + nums [j ];
16
+ i ++ ;
17
+ j -- ;
18
+ }
19
+ if (i == j ) {
20
+ ans += nums [i ];
21
+ }
22
+ return ans ;
23
+ }
Original file line number Diff line number Diff line change
1
+ impl Solution {
2
+ pub fn find_the_array_conc_val ( nums : Vec < i32 > ) -> i64 {
3
+ let n = nums. len ( ) ;
4
+ let mut ans = 0 ;
5
+ let mut i = 0 ;
6
+ let mut j = n - 1 ;
7
+ while i < j {
8
+ ans += format ! ( "{}{}" , nums[ i] , nums[ j] ) . parse :: < i64 > ( ) . unwrap ( ) ;
9
+ i += 1 ;
10
+ j -= 1 ;
11
+ }
12
+ if i == j {
13
+ ans += nums[ i] as i64 ;
14
+ }
15
+ ans
16
+ }
17
+ }
Original file line number Diff line number Diff line change
1
+ function findTheArrayConcVal ( nums : number [ ] ) : number {
2
+ const n = nums . length ;
3
+ let ans = 0 ;
4
+ let i = 0 ;
5
+ let j = n - 1 ;
6
+ while ( i < j ) {
7
+ ans += Number ( `${ nums [ i ] } ${ nums [ j ] } ` ) ;
8
+ i ++ ;
9
+ j -- ;
10
+ }
11
+ if ( i === j ) {
12
+ ans += nums [ i ] ;
13
+ }
14
+ return ans ;
15
+ }
You can’t perform that action at this time.
0 commit comments