---
# System prepended metadata

title: 20-Valid Parentheses
tags: [Easy]

---

# 20-Valid Parentheses
###### tags: `Easy`
## Question
https://leetcode.com/problems/valid-parentheses/
## Key
## Reference
## Solution
```cpp=
class Solution {
public:
    bool isValid(string s) {
        stack<char> stk;
        for (char c : s) {
            if (c == '(' || c == '[' || c == '{') {
                stk.push(c);
            } else {
                if (stk.empty() || c == ')' && stk.top() != '(' || c == ']' && stk.top() != '[' || c == '}' && stk.top() != '{') {
                    return false;
                }
                stk.pop();
            }
        }
        return stk.empty();
    }
};
```