0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

NeetCode_Valid Parentheses

Posted at

はじめに

転職の内定が決まった。
しかし、ある会社でコーディングテストがあったが
全く歯が立たんかった。
克服したいので、NeetCodeを少しずつ進めていく。
ひとまずEasyのものから。
その際の回答に必要だった知識や気づきを書いていこうと思う。

挑戦した問題

問題の概要

You are given a string s consisting of the following characters: '(', ')', '{', '}', '[' and ']'.

The input string s is valid if and only if:

Every open bracket is closed by the same type of close bracket.
Open brackets are closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.
Return true if s is a valid string, and false otherwise.

Example

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

Output: true

回答の流れ

  • Loop
    • 成立するかっこのペアを探す
    • ある場合:対象のかっこペアを文字列から削除
  • Loop
  • 文字列が空になったかどうかを返す

回答のために必要だった知識

// 
+ 成立するかっこのペアを探す
+ ある場合:対象のかっこペアを文字列から削除
↑が思いつかなかった
知識というよりも問題の分析が必要だった
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?