Skip to content

Commit 39d4981

Browse files
committed
chore: add daily leetcode post [2562]找出数组的串联值_translated
1 parent 62b4e8c commit 39d4981

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: 2562.Find the series of the array
3+
date: '2024.01.01 0:00'
4+
tags:
5+
- Python
6+
- answer
7+
- Array
8+
- Double pointer
9+
- simulation
10+
abbrlink: b625a0e1
11+
---
12+
# topic:
13+
14+
[2562.Find the series of the array.md](https://leetcode-cn.com/problems/find-the-concatenation-of-an-array/)
15+
# Thought:
16+
This question andquiz4very similar,都是Double pointer。
17+
I made a mistake when I did this question,When calculating the right pointer, the negative index is calculated`right = -left + 1`,It is difficult to calculate the relationship between positive indexes,So replaced`right = len(nums) - 1 - left`
18+
# Code:
19+
```python
20+
class Solution:
21+
def findTheArrayConcVal(self, nums: List[int]) -> int:
22+
sums = 0
23+
for left in range(len(nums)):
24+
right = len(nums) - 1 - left
25+
if left == right:
26+
sums += nums[left]
27+
break
28+
elif left < right:
29+
sums += int(str(nums[left]) + str(nums[right]))
30+
return sums
31+
```

0 commit comments

Comments
 (0)