if stk else [-1]
를 추가하지 않았다.
아쉽다!
def solution(arr):
i=0
stk = []
for num in arr:
if len(stk) == 0:
stk.append(num)
elif len(stk) != 0 and stk[-1] == num:
stk.pop()
i+=1
else:
stk.append(num)
i+=1
return stk if stk else [-1]
def solution(arr):
stk = []
for i in range(len(arr)):
if stk and stk[-1] == arr[i]:
stk.pop()
else:
stk.append(arr[i])
return stk or [-1]