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?

ValidAnagram_NeetCode

Posted at

はじめに

転職の内定が決まった。
しかし、ある会社でコーディングテストがあったが
全く歯が立たんかった。
克服したいので、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);
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?