Skip to content

Commit 6f65bb7

Browse files
Merge pull request youngyangyang04#805 from hailincai/master
增加java版本---分割平衡字符串
2 parents f0fb65b + 7822528 commit 6f65bb7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

problems/1221.分割平衡字符串.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ public:
9393
## Java
9494
9595
```java
96+
class Solution {
97+
public int balancedStringSplit(String s) {
98+
int result = 0;
99+
int count = 0;
100+
for (int i = 0; i < s.length(); i++) {
101+
if (s.charAt(i) == 'R') count++;
102+
else count--;
103+
if (count == 0) result++;
104+
}
105+
return result;
106+
}
107+
}
96108
```
97109

98110
## Python

0 commit comments

Comments
 (0)