๋ฌธ์
์ฝ๋
class Solution {
public:
bool isValid(string s) {
stack<char>st;
for(int i=0; i<s.length(); i++){
char inp = s[i];
if(st.empty()) st.push(inp);
else{
char top = st.top();
if(top=='('&&inp==')') st.pop();
else if(top=='{'&&inp=='}') st.pop();
else if(top=='['&&inp==']') st.pop();
else st.push(inp);
}
}
if(st.empty()) return true;
else return false;
}
};
'Algorithm ๐ง๐ปโ๐ป > Leetcode' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leetcode,c++] Best Time to Buy and Sell Stock (0) | 2021.11.10 |
---|---|
[Leetcode,c++] Climbing Stairs (0) | 2021.11.09 |
[Leetcode,c++] Maximum Subarray (0) | 2021.11.09 |
[Leetcode,c++] Palindrome Number (0) | 2021.11.09 |
[Leetcode,c++] Search Insert Position (0) | 2021.11.09 |
[Leetcode,c++] Find the City With the Smallest Number of Neighbors at a Threshold Distance (0) | 2021.11.07 |
๋๊ธ