はじめに
転職の内定が決まった。
しかし、ある会社でコーディングテストがあったが
全く歯が立たんかった。
克服したいので、NeetCodeを少しずつ進めていく。
ひとまずEasyのものから。
その際の回答に必要だった知識や気づきを書いていこうと思う。
挑戦した問題
問題の概要
Given two strings s and t, return true if the two strings are anagrams of each other, otherwise return false.
An anagram is a string that contains the exact same characters as another string, but the order of the characters can be different.
Example
Input: s = "racecar", t = "carrace"
Output: true
回答の流れ
- string をchar[]に変換する
- Array.Sortで並びかえ
- sとtの並び替え結果が同じならOK
回答のために必要だった知識
// ToCharArrayでstring->char[]
char[] sChar=s.ToCharArray();
// Array.Sortで配列の並び替え
Array.Sort(sChar);
// SequenceEqualで並びを考慮したイコール
sChar.SequenceEqual(tChar);