본문 바로가기
알고리즘/소스코드

KOREATECH 1027: 인접한 문자 제거하기 HARD

by cjw.git 2020. 12. 10.

Link : judge.koreatech.ac.kr/problem.php?id=1027


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from sys import stdin
 
 
def solution(s):
    stack = []
    for idx, char in enumerate(s):
        if len(stack) < 1:
            stack.append(char)
        else:
            if char == stack[len(stack)-1]:
                stack.pop()
            else:
                stack.append(char)
 
    return ''.join(stack)
 
 
 
testcase = int(stdin.readline().strip())
while testcase:
    data = stdin.readline().strip()
    print(solution(data))
 
    testcase-=1
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

댓글