Write a program to find Valid Anagram || Leetcode Solution || day 4 challenge

 Given two string and return a true value if an anagram otherwise return false 



Approach and Algorithm :


This problem is very simple and it is used to simple and pretty approach. 

Step 1: from the beginning, we have sorted the couple string

Step 2: After that, we are returned both strings are equal 

Code 

class Solution {
public:
    bool isAnagram(string s, string t) {
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());
        return s==t;
    }
};

Post a Comment

0 Comments