DEV Community

Haripriya V
Haripriya V

Posted on

ASSIGNMENT 14

  1. Valid Anagram

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

CODE:

`class Solution:
def isAnagram(self, s, t):
if len(s) != len(t):
return False

    arr = [0] * 26

    for i in range(len(s)):
        arr[ord(s[i]) - ord('a')] += 1
        arr[ord(t[i]) - ord('a')] -= 1

    for check in arr:
        if check != 0:
            return False
    return True`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)