From 78225288cf29223a5e2c7563a0a2cfa72da3fb6f Mon Sep 17 00:00:00 2001 From: hailincai Date: Fri, 1 Oct 2021 14:16:45 -0400 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0java=E7=89=88=E6=9C=AC---?= =?UTF-8?q?=E5=88=86=E5=89=B2=E5=B9=B3=E8=A1=A1=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add java implementation --- problems/1221.分割平衡字符串.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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