File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ answer = ''
2+ def u_notcorrect (u ,v ):
3+ #4-4 자르고 -> 뒤집기
4+ u = list (u [1 :- 1 ]) # 4-4
5+ if bool (u ) :
6+ for i in range (len (u )):
7+ if u [i ]== ")" :
8+ u [i ] = "("
9+ else :
10+ u [i ] = ")"
11+
12+ u = "" .join (u )
13+ # 4-1, 4-2,4-3
14+ tmp = '(' + cut_wuv (v ) + ')' + str (u )
15+ return tmp
16+
17+
18+ def isCorrectString (u ) : # u = p[s:e+1]
19+ count = 0
20+ for s in u :
21+ if s == "(" :
22+ count += 1
23+ elif s == ")" :
24+ count -= 1
25+ if count < 0 :
26+ return False
27+ return count == 0
28+
29+ def cut_wuv (w ):
30+ global answer
31+ # 1. 빈 문자열 -> 빈 문자열
32+ if w == "" :
33+ return ""
34+ #2 w = u+v로 나누기
35+ e = 0 #end idx 가리키는 two point
36+ while e < len (w ):
37+ e += 1
38+ # u 구하기 #2
39+ if w [:e + 1 ].count ('(' ) == w [:e + 1 ].count (')' ):
40+ w = w [:] ;u = w [:e + 1 ] ; v = w [e + 1 :]
41+ break
42+
43+ # 3.
44+ if not isCorrectString (u ): #4올바른 괄호 문자열 x(onlt 균형 잡힌 문자열)
45+ answer += str (u_notcorrect (u ,v ))
46+ return answer
47+
48+ else : #3 u 가 올바른 괄호 문자열
49+ answer = str (u ) + cut_wuv (v )
50+ return answer
51+
52+
53+ def solution (p ):
54+ global answer
55+ answer = cut_wuv (p )
56+ return answer
You can’t perform that action at this time.
0 commit comments