564. Check Balanced Parentheses

EasyStackStackString

Given a string s containing only the characters '(' and ')', determine whether the parentheses are balanced — every opening parenthesis has a matching closing one in the correct order. Return true or false. The input is JSON {s}.

Input: JSON {s}.

Output: Boolean — true or false.

Examples

Example 1
Input: {"s":"(()())"}
Output: true
Explanation: Every parenthesis is matched.
Example 2
Input: {"s":"(()"}
Output: false
Explanation: One unmatched opening.
Example 3
Input: {"s":")("}
Output: false
Explanation: Closes before it opens.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →