| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- react
- This
- github
- JS
- 함수
- 선택자
- gitCLI
- 햇소
- ES6+
- Python
- next.js
- learn next.js
- 최적화
- array
- object
- API
- 우아한테코톡
- dev
- es6
- hooks
- ChatGPT
- hatso
- AI
- DOM
- 변수
- CSS
- ES5+
- html5
- JavaScript
- git
Archives
- Today
- Total
codinghatso
알고리즘 with python.07 본문
올바른 괄호
"("열린 괄호가 나온 횟수만큼 ")" 닫힌 괄호가 나와야 올바른 괄호입니다.
괄호의 계수가 같더라도 ")"닫힌 괄호가 먼저 나왔다면 틀린 괄호입니다.
코드
s = "(())()"
def is_correct_parenthesis(string):
stack = []
for i in range(len(string)):
if string[i] == "(":
stack.append(i) # 어떤 값이 들어가도 상관 x ( 여부 저장이기 때문이다.
elif string[i] == ")": # []
if len(stack) == 0:
return False
else:
stack.pop()
if len(stack) == 0:
return True
else:
return False
return
print(is_correct_parenthesis(s)) # True 를 반환해야 합니다!
'코테일지' 카테고리의 다른 글
| 알고리즘 with python.08 (0) | 2021.06.13 |
|---|---|
| 알고리즘 with python.06 (0) | 2021.06.13 |
| 알고리즘 with python.05 (0) | 2021.05.30 |
| 알고리즘 with python.04 (0) | 2021.05.30 |
| 알고리즘 with python.03 (0) | 2021.05.30 |
Comments