You are viewing a single comment's thread. Return to all comments →
Python 3
def anagram(s): # Write your code here if len(s) % 2 == 1: return -1 t_a = [0 for _ in range(26)] t_b = [0 for _ in range(26)] i = 0 j = len(s) - 1 ord_a = ord('a') while i < j: t_a[ord(s[i])-ord_a] += 1 t_b[ord(s[j])-ord_a] += 1 i += 1 j -= 1 diff = 0 for a, b in zip(t_a, t_b): diff += abs(a - b) return diff // 2
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 →
Python 3