はじめに
転職の内定が決まった。
しかし、ある会社でコーディングテストがあったが
全く歯が立たんかった。
克服したいので、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
- 文字列が空になったかどうかを返す
回答のために必要だった知識
//
+ 成立するかっこのペアを探す
+ ある場合:対象のかっこペアを文字列から削除
↑が思いつかなかった
知識というよりも問題の分析が必要だった