프로그래머스 2단계 "짝지어 제거하기"

sanha_OvO·2021년 6월 16일
0

Algorithm

목록 보기
54/84

문제

프로그래머스 2단계 짝지어 제거하기


풀이

스택을 사용하면 쉬운 문제!


Python 코드

def solution(s):
  stack = []
  for x in s:
    stack.append(x)
    try:
      if stack[-1] == stack[-2]:
        stack.pop()
        stack.pop() 
    except:
      continue
  if stack:
    return 0
  else:
    return 1
profile
Web Developer / Composer

0개의 댓글