Merge pull request #805 from hailincai/master

增加java版本---分割平衡字符串
This commit is contained in:
程序员Carl 2021-10-03 09:57:38 +08:00 committed by GitHub
commit 6f65bb71d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -93,6 +93,18 @@ public:
## Java
```java
class Solution {
public int balancedStringSplit(String s) {
int result = 0;
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'R') count++;
else count--;
if (count == 0) result++;
}
return result;
}
}
```
## Python