|
| 1 | +<h2><a href="https://leetcode.com/problems/valid-parentheses">20. Valid Parentheses</a></h2><h3>Easy</h3><hr><p>Given a string <code>s</code> containing just the characters <code>'('</code>, <code>')'</code>, <code>'{'</code>, <code>'}'</code>, <code>'['</code> and <code>']'</code>, determine if the input string is valid.</p> |
| 2 | + |
| 3 | +<p>An input string is valid if:</p> |
| 4 | + |
| 5 | +<ol> |
| 6 | +<li>Open brackets must be closed by the same type of brackets.</li> |
| 7 | +<li>Open brackets must be closed in the correct order.</li> |
| 8 | +<li>Every close bracket has a corresponding open bracket of the same type.</li> |
| 9 | +</ol> |
| 10 | + |
| 11 | +<p> </p> |
| 12 | +<p><strong class="example">Example 1:</strong></p> |
| 13 | + |
| 14 | +<div class="example-block"> |
| 15 | +<p><strong>Input:</strong> <span class="example-io">s = "()"</span></p> |
| 16 | + |
| 17 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 18 | +</div> |
| 19 | + |
| 20 | +<p><strong class="example">Example 2:</strong></p> |
| 21 | + |
| 22 | +<div class="example-block"> |
| 23 | +<p><strong>Input:</strong> <span class="example-io">s = "()[]{}"</span></p> |
| 24 | + |
| 25 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 26 | +</div> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<div class="example-block"> |
| 31 | +<p><strong>Input:</strong> <span class="example-io">s = "(]"</span></p> |
| 32 | + |
| 33 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 34 | +</div> |
| 35 | + |
| 36 | +<p><strong class="example">Example 4:</strong></p> |
| 37 | + |
| 38 | +<div class="example-block"> |
| 39 | +<p><strong>Input:</strong> <span class="example-io">s = "([])"</span></p> |
| 40 | + |
| 41 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 42 | +</div> |
| 43 | + |
| 44 | +<p><strong class="example">Example 5:</strong></p> |
| 45 | + |
| 46 | +<div class="example-block"> |
| 47 | +<p><strong>Input:</strong> <span class="example-io">s = "([)]"</span></p> |
| 48 | + |
| 49 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 50 | +</div> |
| 51 | + |
| 52 | +<p> </p> |
| 53 | +<p><strong>Constraints:</strong></p> |
| 54 | + |
| 55 | +<ul> |
| 56 | +<li><code>1 <= s.length <= 10<sup>4</sup></code></li> |
| 57 | +<li><code>s</code> consists of parentheses only <code>'()[]{}'</code>.</li> |
| 58 | +</ul> |
0 commit comments