Skip to content

Commit b929cb9

Browse files
authored
Create find-anagram-mappings.py
1 parent d5c4309 commit b929cb9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python/find-anagram-mappings.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
class Solution(object):
5+
def anagramMappings(self, A, B):
6+
"""
7+
:type A: List[int]
8+
:type B: List[int]
9+
:rtype: List[int]
10+
"""
11+
lookup = collections.defaultdict(collections.deque)
12+
for i, n in enumerate(B):
13+
lookup[n].append(i)
14+
result = []
15+
for n in A:
16+
result.append(lookup[n].popleft())
17+
return result

0 commit comments

Comments
 (0)