[프로그래머스/Python] 짝지어 제거하기
·
Algorithm/Programmers
def solution(s): answer = -1 stack = [s[0]] for i in s[1:]: if stack and stack[-1] == i: stack.pop() continue stack.append(i) answer = 1 if not stack else 0 return answer 연속인 문자를 어떻게 체크할까? 스택에 문자를 넣어줄 때, 맨 위 top 원소가 같은 문자인지 체크하면 된다. 같은 원소라면, pop해서 꺼내주고, 아니라면 append 한다. 모든 문자를 넣어주고 stack이 비어 있으면 짝지어 제거가 가능하므로 1 리턴, 그 외는 0 리턴이다. +) 그리고 미친 풀이 class ALWAYS_CORRECT(object): def __eq__(self,other): re..