242. Valid Anagram

Problem:blog

Given two strings s and t, write a function to determine if t is an anagram of s.string

For example,
s = "anagram", t = "nagaram", return true.
s = "rat", t = "car", return false. it

Note:
You may assume the string contains only lowercase alphabets.io

 

A possible answer:function

first:sortclass

second: comparesort

class Solution {
public:
    bool isAnagram(string s, string t) {
        sort(s.begin(), s.end());
        sort(t.begin(), t.end());
        return s == t;
    }
};
相关文章
相关标签/搜索