File tree Expand file tree Collapse file tree 1 file changed +99
-0
lines changed Expand file tree Collapse file tree 1 file changed +99
-0
lines changed Original file line number Diff line number Diff line change
1
+ # ์ฐ๊ด ๋งํฌ
2
+ - [ ๋ฌธ์ ํ์ด ์ค์ผ์ค] ( https://github.com/orgs/DaleStudy/projects/6/views/5 )
3
+ - [ ๋ต์ ์ฝ๋ ์ ์ถ๋ฒ] ( https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C )
4
+
5
+ # Problem
6
+ - ๋ฌธ์ ๋งํฌ : https://leetcode.com/problems/valid-parentheses/description/
7
+ - ๋ฌธ์ ์ด๋ฆ : valid parentheses
8
+ - ๋ฌธ์ ๋ฒํธ : 20
9
+ - ๋์ด๋ : easy
10
+ - ์นดํ
๊ณ ๋ฆฌ :
11
+
12
+ # ๋ฌธ์ ์ค๋ช
13
+
14
+
15
+
16
+ # ์์ด๋์ด
17
+ - stack์ ํตํ ์ ํจ์ฑ ์ฒดํฌ
18
+ - brute force
19
+
20
+ # โ
์ฝ๋ (Solution)
21
+
22
+
23
+ ``` cpp
24
+ class Solution {
25
+ public:
26
+ bool isValid(string s) {
27
+ stack<char > st;
28
+ for(int i=0;i<s.size();i++){
29
+ auto cur = s[ i] ;
30
+ if(cur == '(' || cur == '{' || cur == '[ '){
31
+ st.push(cur);
32
+ continue;
33
+ }else{
34
+ if(st.size()==0){
35
+ return false;
36
+ }
37
+ if(cur == '] '){
38
+ if(st.top() == '[ '){
39
+ st.pop();
40
+ continue;
41
+ }else{
42
+ return false;
43
+ }
44
+ }else if(cur == '}'){
45
+ if(st.top()=='{'){
46
+ st.pop();
47
+ continue;
48
+ }else{
49
+ return false;
50
+ }
51
+ }else {
52
+ if(st.top()=='('){
53
+ st.pop();
54
+ continue;
55
+ }else{
56
+ return false;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ return st.size()==0;
62
+ }
63
+ };
64
+
65
+
66
+ ```
67
+
68
+ ### ๊ฐ๋ตํ
69
+ ```cpp
70
+ class Solution {
71
+ public:
72
+ bool isValid(string s) {
73
+ stack<char> st;
74
+ for (char c : s) {
75
+ if (c == '(') st.push(')');
76
+ else if (c == '{') st.push('}');
77
+ else if (c == '[') st.push(']');
78
+ else {
79
+ if (st.empty() || st.top() != c) return false;
80
+ st.pop();
81
+ }
82
+ }
83
+ return st.empty();
84
+ }
85
+ };
86
+ ```
87
+
88
+ # ๐ ์ฝ๋ ์ค๋ช
89
+
90
+
91
+ # ์ต์ ํ ํฌ์ธํธ (Optimality Discussion)
92
+ - ๊น๋ํ๊ฒ ๋ง๋ฆ
93
+ # ๐งช ํ
์คํธ & ์ฃ์ง ์ผ์ด์ค
94
+
95
+ # ๐ ๊ด๋ จ ์ง์ ๋ณต์ต
96
+
97
+ # ๐ ํ๊ณ
98
+
99
+
You canโt perform that action at this time.
0 commit comments