herrDeng網內搜尋

自訂搜尋

Ads

2024年2月6日 星期二

Python C++ hash table速解Leetcode 49 Group Anagrams


Python C++ hash table速解Leetcode 49  Group Anagrams
Leetcode今天是老題目49. Group Anagrams,解法很多種,不過弄清楚anagram就是排列,一個簡易又快速的解答就出爐了
s is anagram of t  ⟺ freq(s)=freq(t)  ⟺ sorted(s)=sorted(t)
In other words, s is a permutation of t.
-----
There are many ways to solve Leetcode's old problem 49. Group Anagrams, but once you figure out that anagrams are arrangements of the same set of letters, a simple and quick answer becomes available.

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章