diff --git a/problems/1221.分割平衡字符串.md b/problems/1221.分割平衡字符串.md index cec49d0b..bc1f1fc4 100644 --- a/problems/1221.分割平衡字符串.md +++ b/problems/1221.分割平衡字符串.md @@ -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