You are viewing a single comment's thread. Return to all comments →
simple and fullly def anagram(s): t=0 n=len(s) if n%2!=0: return -1 a=s[:n//2] b=s[n//2:] dicta=dict() dictb=dict() for i in range(n//2): if a[i] not in dicta: dicta[a[i]]=1 else: dicta[a[i]]+=1 if b[i] not in dictb: dictb[b[i]]=1 else: dictb[b[i]]+=1 for i in dicta: if i in dictb: if dicta[i]>=dictb[i]: t+=dictb[i] else: t+=dicta[i] t=n//2-t return t
Seems like cookies are disabled on this browser, please enable them to open this website
Anagram
You are viewing a single comment's thread. Return to all comments →