Grace
grace's dev_note
Grace
전체 방문자
오늘
어제
  • 분류 전체보기
    • FrontEnd
      • Next.js
      • React
      • ReactNativ..
      • Vue
    • Javascript
      • 러닝 자바스크립트
      • 모던 자바스크립트
    • CS
    • DataScienc..
      • Data Struc..
      • LeetCode
    • BackEnd
      • Express
      • Node.js
      • Nest.js
    • DevOps
      • Docker
    • 매일메일
    • 회고
    • 코드캠프

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • nest.js
  • 자바스크립트
  • Vue3
  • pinia
  • 함수
  • postgres
  • tanstack
  • vitejs
  • Vite
  • Express
  • Vue.js
  • backend
  • 번들러
  • 알고리즘
  • React Native
  • javascript
  • Vue
  • node.js
  • PostgreSQL
  • vue-query

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Grace

grace's dev_note

DataScience/LeetCode

[Easy] Valid Parentheses

2022. 11. 2. 09:06

Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.
  3. Every close bracket has a corresponding open bracket of the same type.

 

Example 1:

Input: s = "()"
Output: true

Example 2:

Input: s = "()[]{}"
Output: true

Example 3:

Input: s = "(]"
Output: false

 

Constraints:

  • 1 <= s.length <= 104
  • s consists of parentheses only '()[]{}'.
var isValid = function(s) {
  function pop(s){
      if(!s) return true
      if(s.includes("()") || s.includes("[]") || s.includes("{}")) {
        s = s.replaceAll("()", "")
        s = s.replaceAll("[]", "")
        s = s.replaceAll("{}", "")
      } else {
          return false
      }
      return pop(s)
    }
  return pop(s)
};
저작자표시 비영리 변경금지 (새창열림)

'DataScience > LeetCode' 카테고리의 다른 글

[Easy] Sqrt(x)  (0) 2022.11.17
[Easy] Plus One  (0) 2022.11.16
[Easy] Roman to Integer  (0) 2022.10.12
[Easy] Palindrome Number  (0) 2022.10.11
[Easy] Two Sum  (0) 2022.10.06
    'DataScience/LeetCode' 카테고리의 다른 글
    • [Easy] Sqrt(x)
    • [Easy] Plus One
    • [Easy] Roman to Integer
    • [Easy] Palindrome Number
    Grace
    Grace
    기술 및 회고 블로그

    티스토리툴바