Given a string containing just the characters
(
,)
,{
,}
,[
and]
, determine if the input string is valid.For an input string to be valid:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Note that an empty string is considered valid.
###Example 1:
Example 1:
Input:
()
Output: true###Example 2:
Example 2:
Input:
()[]{}
Output: true###Example 3:
Example 3:
Input:
(]
Output: false###Example 4:
Example 4:
Input:
([)]
Output: false###Example 5:
Example 5:
Input:
{[]}
Output: true
Given a string containing just the characters
(
,)
,{
,}
,[
and]
, determine if the input string is valid.For an input string to be valid:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Note that an empty string is considered valid.
###Example 1:
Input:
()
Output: true###Example 2:
Input:
()[]{}
Output: true###Example 3:
Input:
(]
Output: false###Example 4:
Input:
([)]
Output: false###Example 5:
Input:
{[]}
Output: true
Given a string containing just the characters
(
,)
,{
,}
,[
and]
, determine if the input string is valid.For an input string to be valid:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Note that an empty string is considered valid.
Example 1:
Input:
()
Output: trueExample 2:
Input:
()[]{}
Output: trueExample 3:
Input:
(]
Output: falseExample 4:
Input:
([)]
Output: falseExample 5:
Input:
{[]}
Output: true
- 87.3k
- 14
- 104
- 322
Given a string containing just the characters '('
(
, ')')
, '{'{
, '}'}
, '['[
and ']']
, determine if the input string is valid.AnFor an input string isto be valid if:
Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid.
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Example 1:Note that an empty string is considered valid.
Input: "()" Output###Example 1: true
Example 2Input:
()
Output: trueInput: "()[]{}" Output###Example 2: true
Example 3Input:
()[]{}
Output: trueInput: "(]" Output###Example 3: false
Example 4Input:
(]
Output: falseInput: "([)]" Output###Example 4: false
Example 5Input:
([)]
Output: false###Example 5:
Input: "{[]}" Output
{[]}
Output: true
Please review coding style as it was a job interview with 30 minutes to code. thanks!
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid.
Example 1:
Input: "()" Output: true
Example 2:
Input: "()[]{}" Output: true
Example 3:
Input: "(]" Output: false
Example 4:
Input: "([)]" Output: false
Example 5:
Input: "{[]}" Output: true
Please review coding style as it was a job interview with 30 minutes to code. thanks!
Given a string containing just the characters
(
,)
,{
,}
,[
and]
, determine if the input string is valid.For an input string to be valid:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
Note that an empty string is considered valid.
###Example 1:
Input:
()
Output: true###Example 2:
Input:
()[]{}
Output: true###Example 3:
Input:
(]
Output: false###Example 4:
Input:
([)]
Output: false###Example 5:
Input:
{[]}
Output: true
Please review coding style as it was a job interview with 30 minutes to code.