Sunday, August 18, 2013

anagrams strings

/* From Cracking the Coding Interview 1-4 */
/* Write a method to decide if two strings are anagrams or not. */
/* anagram : a word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman. */

bool isAnagrams(string word1, string word2) {
    string w1 = word1, w2 = word2;
    sort(w1.begin(), w1.end());
    sort(w2.begin(), w2.end());
    return w1 == w2;
   

}

No comments:

Post a Comment