-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathvalid-parentheses.md
45 lines (32 loc) · 1.12 KB
/
valid-parentheses.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<p>Given a string 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>
<p>An input string is valid if:</p>
<ol>
<li>Open brackets must be closed by the same type of brackets.</li>
<li>Open brackets must be closed in the correct order.</li>
</ol>
<p>Note that an empty string is also considered valid.</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> "()"
<strong>Output:</strong> true
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> "()[]{}"
<strong>Output:</strong> true
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> "(]"
<strong>Output:</strong> false
</pre>
<p><strong>Example 4:</strong></p>
<pre>
<strong>Input:</strong> "([)]"
<strong>Output:</strong> false
</pre>
<p><strong>Example 5:</strong></p>
<pre>
<strong>Input:</strong> "{[]}"
<strong>Output:</strong> true
</pre>