leetcode刷题,总结,记录,备忘 242

leetcode242

Valid Anagram

 

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

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

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

不说了,,很简单,就是判断2个字符串是不是一样的。。

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


你可能感兴趣的:(leetcode刷题,总结,记录,备忘 242)