[HackerRank][Python3] Super Reduced String
2018. 5. 11. 03:41 |
프로그래밍/HackerRank
요즘 틈틈이 알고리즘 기초 공부를 하고 있는데, HackerRank 문제를 풀면서 나의 풀이를 기록으로 남겨보려 한다.
Problem :
https://www.hackerrank.com/challenges/reduced-string/problem
My Solution :
#!/usr/bin/env python3
def super_reduced_string(s, i):
if i < 0:
i = 0
while i < len(s) - 1:
if s[i] == s[i+1]:
return super_reduced_string(s[:i] + s[i+2:], i-1)
i += 1
return s
s = input().strip()
result = super_reduced_string(s, 0)
print(result) if result != '' else print('Empty String')
My Solution2 :
#!/usr/bin/env python3
def super_reduced_string(s):
res = []
for c in s:
if res and c == res[-1]:
res.pop()
else:
res.append(c)
return ''.join(res)
s = input().strip()
result = super_reduced_string(s)
print(result) if result != '' else print('Empty String')
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Big Sorting (0) | 2018.05.29 |
|---|---|
| [HackerRank][Python3] CamelCase (0) | 2018.05.27 |
| [HackerRank][Python3] Journey to the Moon (0) | 2018.05.25 |
| [HackerRank][Python3] Hackerland Radio Transmitters (0) | 2018.05.23 |
| [HackerRank][Python3] Sherlock and Cost (0) | 2018.05.21 |
| [HackerRank][Python3] Maximum Subarray Sum (0) | 2018.05.18 |
| [HackerRank][Python3] Equal (0) | 2018.05.16 |
| [HackerRank][Python3] The Coin Change Problem (0) | 2018.05.15 |
최근에 달린 댓글 최근에 달린 댓글