Given two strings,write a method to decide if one is a permutation of the other.
Example 1:
Input:s1
= "abc",s2
= "bca" Output: true
Example 2:
Input:s1
= "abc",s2
= "bad" Output: false
Note:
0 <= len(s1) <= 100
0 <= len(s2) <= 100
class Solution:
def CheckPermutation(self, s1: str, s2: str) -> bool:
return sorted(s1) == sorted(s2)
class Solution {
public boolean CheckPermutation(String s1, String s2) {
if (s1 == null || s2 == null || s1.length() != s2.length()) {
return false;
}
char[] c1 = s1.toCharArray();
char[] c2 = s2.toCharArray();
Arrays.sort(c1);
Arrays.sort(c2);
return Arrays.equals(c1, c2);
}
}