Class Solution

java.lang.Object
g0001_0100.s0020_valid_parentheses.Solution

public class Solution extends Object
20 - Valid Parentheses.<p>Easy</p> <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> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;()&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;()[]{}&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;(]&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> s = &ldquo;([)]&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> s = &ldquo;{[]}&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>4</sup></code></li> <li><code>s</code> consists of parentheses only <code>'()[]{}'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isValid

      public boolean isValid(String s)