Skip to content

Commit 78bf85c

Browse files
committed
https://leetcode.cn/problems/di-string-match
1 parent 0cf08f5 commit 78bf85c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ leetcode 测试
1010

1111
##### 包含的内容如下
1212

13+
https://leetcode.cn/problems/di-string-match
14+
1315
https://leetcode.cn/problems/reshape-the-matrix/
1416

1517
https://leetcode.cn/problems/sZ59z6/

di-string-match/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default function diStringMatch(s: string): number[] {
2+
const n = s.length, ans = new Array<number>();
3+
let left = 0, right = n;
4+
for (let i = 0; i < n; i++) {
5+
if (s.charCodeAt(i) === "I".charCodeAt(0)) {
6+
ans.push(left++);
7+
} else {
8+
ans.push(right--);
9+
}
10+
}
11+
ans.push(left);
12+
return ans;
13+
}

0 commit comments

Comments
 (0)