File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Time: O(n * l)
2
+ # Space: O(1)
3
+
4
+ import collections
5
+
6
+
7
+ # freq table
8
+ class Solution (object ):
9
+ def removeAnagrams (self , words ):
10
+ """
11
+ :type words: List[str]
12
+ :rtype: List[str]
13
+ """
14
+ result = []
15
+ prev = None
16
+ for x in words :
17
+ cnt = collections .Counter (x )
18
+ if prev and prev == cnt :
19
+ continue
20
+ prev = cnt
21
+ result .append (x )
22
+ return result
23
+
24
+
25
+ # Time: O(n * llogl)
26
+ # Space: O(l)
27
+ import collections
28
+
29
+
30
+ # sort
31
+ class Solution2 (object ):
32
+ def removeAnagrams (self , words ):
33
+ """
34
+ :type words: List[str]
35
+ :rtype: List[str]
36
+ """
37
+ result = []
38
+ prev = None
39
+ for x in words :
40
+ s = sorted (x )
41
+ if prev and prev == s :
42
+ continue
43
+ prev = s
44
+ result .append (x )
45
+ return result
You can’t perform that action at this time.
0 commit comments