let the len of first array be n
it run in O(n)
create 26 letter array cost is constant, count the occuance of each letter in array1 is O(n) check whether the element in array2 is indeed in array1 is O(n)
Totally O(n)
let the len of first array be n
it run in O(n)
create 26 letter array cost is constant, count the occuance of each letter in array1 is O(n) check whether the element in array2 is indeed in array1 is O(n)
Totally O(n)
import string | |
def isSubset(arr1,arr2): | |
d = dict.fromkeys(string.ascii_lowercase, 0) | |
for i in arr1: | |
d[i]+=1 | |
for j in arr2: | |
if d[j] == 0: | |
return False |