LeetCode-242-有效的字母異位詞

如果兩個字母數組的值完全一致,那麼對其進行排列後,兩個數組應該完全相同。

調用<algorithm>中的sort函數。

#include <iostream>
#include <algorithm>
using namespace std;

bool isAnagram(string s,string t){
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    return s==t;
}
int main(){
    cout<<isAnagram("anagram","nagaram")<<endl;
    return 0;
}

如果報錯:‘sort’ was not declared in this scope.

錯誤原因:缺少引用

解決方案:#include<algorithm>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章