We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 834f9d8 commit 37cc227Copy full SHA for 37cc227
docs/data-structure/array/README.md
@@ -816,6 +816,24 @@ class Solution(object):
816
return ans.values()
817
```
818
819
+普通写法,序列化为字符串:
820
+
821
+```python
822
+class Solution:
823
+ def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
824
+ table = dict()
825
+ for string in strs:
826
+ sort_string = "".join(sorted(string))
827
+ if sort_string not in table:
828
+ table[sort_string] = []
829
+ table[sort_string].append(string)
830
+ ans = [x for x in table.values()]
831
+ return ans
832
+```
833
834
+- 时间复杂度:O(n*klogk)(`n` 是 `strs` 长度,`k` 是 `strs` 中字符串的最大长度)
835
+- 空间复杂度:O(n*k),存储在 `ans` 中的所有信息内容
836
837
### 参考资料
838
839
- [Python中collections.defaultdict()使用](https://www.jianshu.com/p/26df28b3bfc8)
0 commit comments