[LeetCode] Interview Question 01.02. Determine whether each is a character rearrangement (C++)

1 topic description

Given two strings s1 and s2, please write a program to determine whether the characters of one string can be changed into another string after the characters are rearranged.

2 Example description

2.1 Example 1

Input: s1 = "abc", s2 = "bca"
Output: true

2.2 Example 2

Input: s1 = "abc", s2 = "bad"
Output: false

3 Problem solving tips

0 <= len(s1) <= 100
0 <= len(s2) <= 100

4 Problem-solving ideas

Judge after sorting.

5 Detailed source code (C++)

class Solution {
    
    
public:
    bool CheckPermutation(string s1, string s2) {
    
    
        sort( s1.begin() , s1.end() ) ;
        sort( s2.begin() , s2.end() ) ;
        return s1 == s2 ;
    }
};

Guess you like

Origin blog.csdn.net/Gyangxixi/article/details/114416296