[C#][LeetCode][Easy] 242. Valid Anagram

心得:

這題要比較兩個字串是否具有相同字母(不管順序),因為這題比較簡單,所以就嘗試用了許多方式解答。

問題:

Given two strings s and t, write a function to determine if t is an anagram of s.

For example,
s = “anagram”, t = “nagaram”, return true.
s = “rat”, t = “car”, return false.

Note:
You may assume the string contains only lowercase alphabets.

答案:

  • LinQ – OrderBy
  • LinQ – Sort
  • Normal – Array.Sort
  • Normal – 硬幹 (會 Time Limit Exceeded)

參考:

  1. (C#)用迴圈印出字母A到Z


這裡的資訊對您有用嗎?歡迎斗內給我