本文主要是介绍LeetCode - 242,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:https://leetcode.com/problems/valid-anagram/description/
先sort排序,再compare比较大小。
class Solution {
public:bool isAnagram(string s, string t) {int slength = s.length();int tlength = t.length();if(slength != tlength){return false;}sort(s.begin(),s.end());sort(t.begin(),t.end());if(s.compare(t) == 0){return true;}else{return false;}}
};
这篇关于LeetCode - 242的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!