Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d7b2743

Browse files
1221. Split a String in Balanced Strings
1 parent eb5f0ae commit d7b2743

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎split-a-string-in-balanced-strings.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Runtime: 0 ms
2+
// Memory Usage: 8.3 MB
3+
class Solution {
4+
public:
5+
int balancedStringSplit(string s) {
6+
int count = 0;
7+
int res = 0;
8+
for (char c : s) {
9+
if (c == 'L') count++;
10+
else count--;
11+
12+
if (count == 0) res ++;
13+
}
14+
return res;
15+
}
16+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /