Checking if two strings are permutations of each other

前端 未结 30 994
感情败类
感情败类 2020-12-05 08:19

How to determine if two strings are permutations of each other

30条回答
  •  情深已故
    2020-12-05 09:09

    bool is_permutation1(string str1, string str2) {
        sort(str1.begin(), str1.end());
        sort(str2.begin(), str2.end());
        for (int i = 0; i < str1.length(); i++) {    
            if (str1[i] != str2[i]) {
                return false;
            }
        }
        return true;
    }
    

提交回复
热议问题