8000 * Done with "1963. Minimum Number of Swaps to Make the String Balanced". · garciparedes/leetcode@a00091a · GitHub
[go: up one dir, main page]

Skip to content

Commit a00091a

Browse files
committed
* Done with "1963. Minimum Number of Swaps to Make the String Balanced".
1 parent cb3ad67 commit a00091a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def minSwaps(self, s: str) -> int:
3+
counter = 0
4+
5+
ans = 0
6+
for c in s:
7+
if c == "[":
8+
counter += 1
9+
else:
10+
if counter > 0:
11+
counter -= 1
12+
else:
13+
counter += 1
14+
ans += 1
15+
16+
return ans

0 commit comments

Comments
 (0)
0