A very simple solution using python


  • 0
    K
    class Solution:
    # @param {string} s
    # @param {string} t
    # @return {boolean}
    def isAnagram(self, s, t):
        arr_count = [0]*26
        for i in xrange(len(s)):
            idx = ord(s[i]) - ord('a')
            arr_count[idx] += 1
            
        for i in xrange(len(t)):
            idx = ord(t[i]) - ord('a')
            arr_count[idx] -= 1
            
        flag = True
        for i in xrange(len(arr_count)):
            if arr_count[i] == 0:
                continue
            else:
                flag = False
                break
        return flag

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.