728x90
반응형
Go
import "strings"
func solution(s string) (result int) {
result += check(s)
for i := 0; i < len(s) - 1; i++ {
s2 := s[i + 1: len(s)] + s[:i + 1]
result += check(s2)
}
return result
}
func check(s string) int {
sLen := len(s)
for ;; {
s = strings.ReplaceAll(s, "[]", "")
s = strings.ReplaceAll(s, "()", "")
s = strings.ReplaceAll(s, "{}", "")
if sLen == len(s) || len(s) == 0 {
break
}
sLen = len(s)
}
if len(s) == 0 {
return 1
}
return 0
}
Python
def solution(s):
answer = 0
if len(s) % 2 == 1: return 0
for i in range(len(s)):
s = s[1:] + s[0]
if check(s):
answer += 1
return answer
def check(s):
sLength = 0
while sLength != len(s):
sLength = len(s)
s = s.replace("{}", "")
s = s.replace("[]", "")
s = s.replace("()", "")
if len(s) > 0: return False
return True
728x90
반응형
'프로그래머스 > LEVEL 1' 카테고리의 다른 글
음양 더하기 (0) | 2021.11.28 |
---|---|
숫자 문자열과 영단어 (0) | 2021.11.06 |
N개의 최소공배수 (0) | 2021.11.06 |
Go 모의고사 (0) | 2021.10.24 |
나머지가 1이 되는 수 찾기 (0) | 2021.10.16 |