leetcode 面试题 01.02. 判定是否互为字符重排

面试题 01.02. 判定是否互为字符重排

难度简单12

给定两个字符串 s1 和 s2,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。

示例 1:

输入: s1 = "abc", s2 = "bca"
输出: true 
class Solution:
    def CheckPermutation(self, s1: str, s2: str) -> bool:
        return sorted(s1)==sorted(s2)


class Solution:
    def CheckPermutation(self, s1: str, s2: str) -> bool:
        S1 = collections.Counter(s1)
        S2 = collections.Counter(s2)
        return S1 == S2

示例 2:

输入: s1 = "abc", s2 = "bad"
输出: false

你可能感兴趣的:(leetcode)