The definition of correctly paired parentheses means that if it is opened with a '(' character, it must be closed with a ')' character.
For instance,

  • "()()" or "(())()" is a correct parenthesis.
  • ")()(" or "(()(" is an incorrect parenthesis.

Given a string s consisting only of '(' or ')', complete a solution function that returns true if the string s is the correct parenthesis and false if it is not.

  • Length of string s: natural number less than 100,000
  • The string s consists of only '(' or ')'.

s answer
"()()" true
"(())()" true
")()(" false
"(()(" false

Example #1

Same as above example.

Result Stop
Result of [Run Test] or [Submit] will be displayed here
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.