Content-Length: 290990 | pFad | http://github.com/JanaSabuj/Leetcode-solutions/commit/54a152a43eb634d715cfc5ba1d67a533a85991e4

60 Time: 3 ms (46.87%), Space: 6.3 MB (50.94%) - LeetHub · JanaSabuj/Leetcode-solutions@54a152a · GitHub
Skip to content

Commit 54a152a

Browse files
committed
Time: 3 ms (46.87%), Space: 6.3 MB (50.94%) - LeetHub
1 parent e50c93d commit 54a152a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public:
3+
bool isValid(string str) {
4+
// (', ')', '{', '}', '[' and ']'
5+
int n = str.size();
6+
stack<char> st;
7+
8+
for (int i = 0; i < n; i++) {
9+
char c = str[i];
10+
if (c == '(' or c == '{' or c == '[')
11+
st.push(c);
12+
else if (st.empty() || (c == ')' and st.top() != '(') || (c == ']' and st.top() != '[') || (c == '}') and st.top() != '{')
13+
return false;
14+
else
15+
st.pop();
16+
}
17+
18+
return st.empty();
19+
}
20+
};
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/JanaSabuj/Leetcode-solutions/commit/54a152a43eb634d715cfc5ba1d67a533a85991e4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy