Search
๐Ÿป

๊น€๊ธฐํ—Œ

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
300
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
#include<string> using namespace std; bool solution(string s){ int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '(')cnt++; else { if (!cnt)return false; cnt--; } } return !cnt; }
C++
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ
1.
s๋ฅผ ์•ž์—์„œ๋ถ€ํ„ฐ ํƒ์ƒ‰
2.
โ€˜(โ€™ ์ผ ๊ฒฝ์šฐ cnt์— +1
3.
โ€˜)โ€™ ์ผ ๊ฒฝ์šฐ
a.
cnt๊ฐ€ 0์ด๋ผ๋ฉด false return
b.
cnt > 0์ด๋ผ๋ฉด cnt -1
4.
๋ฐ˜๋ณต๋ฌธ์ด ๋๋‚œ ํ›„
a.
cnt๊ฐ€ 0์ด๋ผ๋ฉด return true
b.
cnt > 0์ด๋ผ๋ฉด return false