Given two strings s and t, return true if t is an anagram of s, and false otherwise.
An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
Example 1:
Input: s = "anagram", t = "nagaram" Output: true
Example 2:
Input: s = "rat", t = "car" Output: false
Constraints:
1 <= s.length, t.length <= 5 * 104sandtconsist of lowercase English letters.
class Solution {
public:
bool isAnagram(string s, string t) {
if(s.length() != t.length())
return false;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
if(s == t)
return true;
return false;
}
};
文章描述了一个编程问题,要求编写一个C++函数,判断两个给定字符串s和t是否可以通过重新排列它们的字母构成Anagram。函数通过比较排序后的字符串是否相等来确定答案。
665

被折叠的 条评论
为什么被折叠?



