def solution(s):
S = []
result = True
for i in s:
if i == '(':
S.append(i)
elif S and i == ')' and S[-1] == '(':
S.pop()
elif i == ')':
result = False
break
if S:
result = False
return result
def solution(s):
lst = list(s)
cnt = 0
zero = 0
while lst != ["1"]: # lst가 ["1"]이 될 때까지
zero += lst.count("0") # 0의 갯수 세기
lst = list(bin(lst.count("1"))[2:]) # 1의 갯수를 세고 그 값을 이진수로 바꿔 lst에 다시 저장
cnt += 1 # 한번 했으니까 카운트
return [cnt, zero]
def solution(n):
cnt = 0
for i in range(1, n+1):
sum_n = 0
for j in range(i, n+1):
sum_n += j
if sum_n == n:
cnt += 1
break
if sum_n > n:
break
return cnt
1부터 하나씩 더해가면서 완전탐색하는 방법으로 풀었다!!