mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
增加java版本---分割平衡字符串
Add java implementation
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user