Skip to content

Latest commit

 

History

History
82 lines (46 loc) · 1.33 KB

README_EN.md

File metadata and controls

82 lines (46 loc) · 1.33 KB

中文文档

Description

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:

  1. 0 <= len(s1) <= 100
  2. 0 <= len(s2) <= 100

Solutions

Python3

class Solution:
    def CheckPermutation(self, s1: str, s2: str) -> bool:
        return sorted(s1) == sorted(s2)

Java

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);
    }
}

...