Search

์กฐ์˜ˆ์ง€

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
1800
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
def solution(s): cnt = 0 for i in s: if cnt < 0: return False if i == '(': cnt += 1 else: cnt -= 1 return cnt == 0
Python
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ
for ๋ฌธ์ž์—ด:
cnt๊ฐ€ ์Œ์ˆ˜์ด๋ฉด False
(์ด๋ฉด cnt 1์„ ๋”ํ•œ๋‹ค.
)์ด๋ฉด cnt 1์„ ๋บ€๋‹ค.
cnt๊ฐ€ 0์ด๋ฉด true, ์•„๋‹ˆ๋ฉด false