Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7822528

Browse files
增加java版本---分割平衡字符串
Add java implementation
1 parent 18a9fe0 commit 7822528

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)

AltStyle によって変換されたページ (->オリジナル) /