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 b94efc7

Browse files
committed
[20220817] greedy Runtime: 38 ms / Memory Usage: 13.9 MB
1 parent 13e10de commit b94efc7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 1221. Split a String in Balanced Strings
2+
# https://leetcode.com/problems/split-a-string-in-balanced-strings/
3+
4+
5+
class Solution:
6+
def balancedStringSplit(self, s: str) -> int:
7+
result = 0
8+
lc = 0
9+
rc = 0
10+
11+
for st in list(s):
12+
if st == "L":
13+
lc += 1
14+
else:
15+
rc += 1
16+
if lc == rc:
17+
result += 1
18+
19+
return result
20+
21+
22+
if __name__ == '__main__':
23+
sol = Solution()
24+
print(sol.balancedStringSplit("RLRRLLRLRL"))
25+
print(sol.balancedStringSplit("RLRRRLLRLL"))
26+
print(sol.balancedStringSplit("LLLLRRRR"))

0 commit comments

Comments
(0)

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