Movatterモバイル変換


[0]ホーム

URL:


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

Commita93ccfe

Browse files
authored
Create 1963-minimum-number-of-swaps-to-make-the-string-balanced.py
Create the Python solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=3YDBT9ZrfaU"
1 parenta651870 commita93ccfe

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+
classSolution:
2+
defminSwaps(self,s:str)->int:
3+
extraClose,maxClose=0,0
4+
5+
forcins:
6+
ifc=="[":
7+
extraClose-=1
8+
else:
9+
extraClose+=1
10+
11+
maxClose=max(maxClose,extraClose)
12+
13+
return (maxClose+1)//2# Or math.ceil(maxClose / 2)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp