Skip to content

Commit 319c09b

Browse files
authored
Create Split a String in Balanced Strings.java
1 parent 6f3680d commit 319c09b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int balancedStringSplit(String s) {
3+
int count = 0;
4+
int val = 0;
5+
for (char c : s.toCharArray()) {
6+
val += c == 'L' ? -1 : 1;
7+
if (val == 0) {
8+
count++;
9+
}
10+
}
11+
return count;
12+
}
13+
}

0 commit comments

Comments
 (0)