DEV Community

Ganga Sri V
Ganga Sri V

Posted on

Valid Anagram

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

My Approach:

  1. First I check the length of the both array if its not equal then I return as false because if all the characters are same then there length also must be same.

2.Then I convert the both arrays to character Array and store in another variable so that I can sort and compare then more in easy way and faster way

3.After converting into character Array then I sort the both character Arrays so that I can compare them.

4.By using the equals() function I check is the two character Arrays are same or not based on it results true or false.

Method Used:
Sorting

Top comments (0)