Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liyunrui/5c594c3b7bc3eb17f20b3714792e8ae9 to your computer and use it in GitHub Desktop.
Save liyunrui/5c594c3b7bc3eb17f20b3714792e8ae9 to your computer and use it in GitHub Desktop.
leetcode
class Solution:
def balancedStringSplit(self, s: str) -> int:
balance = 0
n = len(s)
ans = 0
for i in range(n):
if s[i] == "R":
balance+=1
else:
balance-=1
if balance == 0:
ans+=1
return ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment