-
242. Valid Anagram릿코드(LEETCODE) 2020. 2. 12. 16:15반응형
https://leetcode.com/problems/valid-anagram/
Source
28 ms
bool isAnagram(string s, string t) { sort(s.begin(), s.end()); sort(t.begin(), t.end()); return s == t; }
8 ms
class Solution { public: vector<char> getTable(string s) { vector<char> alphabet(27); for (auto a : s) { alphabet[a - 'a']++; } return alphabet; } bool isAnagram(string s, string t) { vector<char> s_table = getTable(s); vector<char> t_table = getTable(t); for (int i = 0; i < s_table.size(); i++) { if (s_table[i] != t_table[i]) { return false; } } return true; } };
반응형'릿코드(LEETCODE)' 카테고리의 다른 글
70. Climbing Stairs (0) 2020.02.12 746. Min Cost Climbing Stairs (0) 2020.02.12 56. Merge Intervals (0) 2020.02.12 520. Detect Capital (0) 2020.02.12 146. LRU Cache (0) 2020.02.12