app.codility.com/demo/results/training6WQ7HN-NGN/
Task Score
100%
Correctness
100%
Performance
100%
Detected time complexity
O(N)
def solution(S):
nest = {"(":")"}
stack = []
for s in S:
if s in nest.keys():
stack.append(s)
elif s in nest.values():
if stack:
stack.pop()
else:
return 0
if not stack:
return 1
else:
return 0
문제를 푸는데 도움이 된 테스트 케이스
')(' '' ')' '(' 'vv' 'v(v)v' |
728x90
반응형
'Problem Solving > Codility' 카테고리의 다른 글
[Python] DisappearingPairs (0) | 2021.07.15 |
---|---|
[Python] 8.1. Dominator (0) | 2021.04.05 |
[Python] 7.2. Fish (0) | 2021.03.29 |
[Python] 7.1. Brackets (0) | 2021.03.27 |
[Python] 6.4. Triangle (0) | 2021.03.26 |
댓글