Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b46bbe1

Browse files
committed
feat: add solutions to lc problem: No.2562
No.2562.Find the Array Concatenation Value
1 parent 8d29144 commit b46bbe1

File tree

5 files changed

+205
-1
lines changed

5 files changed

+205
-1
lines changed

‎solution/2500-2599/2562.Find the Array Concatenation Value/README.md‎

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,16 @@ nums 只有一个元素,所以我们选中 13 并将其加到串联值上,
8282
<!-- 这里可写当前语言的特殊实现逻辑 -->
8383

8484
```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
8695
```
8796

8897
### **Java**
@@ -140,6 +149,76 @@ func findTheArrayConcVal(nums []int) (ans int64) {
140149
}
141150
```
142151

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+
143222
### **...**
144223
145224
```

‎solution/2500-2599/2562.Find the Array Concatenation Value/README_EN.md‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,76 @@ func findTheArrayConcVal(nums []int) (ans int64) {
148148
}
149149
```
150150

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+
151221
### **...**
152222
153223
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /