MCPcopy
hub / github.com/HuberTRoy/leetCode / wordSubsets

Method wordSubsets

Array/WordSubsets.py:62–86  ·  view source on GitHub ↗

:type A: List[str] :type B: List[str] :rtype: List[str]

(self, A, B)

Source from the content-addressed store, hash-verified

60
61class Solution(object):
62 def wordSubsets(self, A, B):
63 """
64 :type A: List[str]
65 :type B: List[str]
66 :rtype: List[str]
67 """
68 dict_A = {i:Counter(i) for i in A}
69 dict_B = {}
70
71 for i in B:
72 c = Counter(i)
73 for j in c:
74 if c.get(j) > dict_B.get(j, 0):
75 dict_B[j] = c.get(j)
76
77 result = []
78
79 for i in dict_A:
80 for j in dict_B:
81 if dict_B[j] > dict_A[i].get(j):
82 break
83 else:
84 result.append(i)
85
86 return result

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected