Skip to content

Commit 0b54cd6

Browse files
committed
https://leetcode.cn/problems/split-a-string-in-balanced-strings/
1 parent bb328ec commit 0b54cd6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-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/split-a-string-in-balanced-strings/
14+
1315
https://leetcode.cn/problems/maximum-xor-after-operations/
1416

1517
https://leetcode.cn/problems/construct-binary-tree-from-string/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function balancedStringSplit(s: string): number {
2+
let ans = 0,
3+
d = 0;
4+
for (let i = 0; i < s.length; ++i) {
5+
const ch = s[i];
6+
if (ch === "L") {
7+
++d;
8+
} else {
9+
--d;
10+
}
11+
if (d === 0) {
12+
++ans;
13+
}
14+
}
15+
return ans;
16+
}

0 commit comments

Comments
 (0)