Skip to content

Commit 5d25f0b

Browse files
committed
6354. 找出数组的串联值
1 parent 113af51 commit 5d25f0b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
|2331|[计算布尔二叉树的值](https://leetcode.cn/problems/evaluate-boolean-binary-tree/)|[JavaScript](./algorithms/evaluate-boolean-binary-tree.js)|Easy|
227227
|2335|[装满杯子需要的最短总时长](https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/)|[JavaScript](./algorithms/minimum-amount-of-time-to-fill-cups.js)|Easy|
228228
|2351|[第一个出现两次的字母](https://leetcode.cn/problems/first-letter-to-appear-twice/)|[JavaScript](./algorithms/first-letter-to-appear-twice.js)|Easy|
229+
|6354|[找出数组的串联值](https://leetcode.cn/problems/find-the-array-concatenation-value/)|[JavaScript](./algorithms/find-the-array-concatenation-value.js)|Easy|
229230
|面试题 04.12|[面试题 04.12. 求和路径](https://leetcode.cn/problems/paths-with-sum-lcci/)|[JavaScript](./algorithms/paths-with-sum-lcci.js)|Medium|
230231
|面试题 02.07|[面试题 02.07. 链表相交](https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/)|[JavaScript](./algorithms/intersection-of-two-linked-lists-lcci.js)|Easy|
231232
|剑指 Offer 05. 替换空格|[剑指 Offer 05. 替换空格](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)|[JavaScript](./algorithms/ti-huan-kong-ge-lcof.js)|Easy|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 6354. 找出数组的串联值
3+
* @param {number[]} nums
4+
* @return {number}
5+
*/
6+
var findTheArrayConcVal = function (nums) {
7+
let result = 0;
8+
let left = 0;
9+
let right = nums.length - 1;
10+
11+
while (left < right) {
12+
const curr = `${nums[left]}${nums[right]}`;
13+
result += Number(curr);
14+
left++;
15+
right--;
16+
}
17+
if (nums.length % 2 !== 0) {
18+
result += nums[left];
19+
}
20+
return result;
21+
};

0 commit comments

Comments
 (0)