题目
给定两个字符串s1和s2,请编写一个程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。
思路
本质上就是判断s1中的字符类别和数目是否和s2中一致。
class Solution:def CheckPermutation(self, s1: str, s2: str) -> bool:s1_ = dict()s2_ = dict()for ch in s1:s1_[ch] = s1_.get(ch, 0) + 1for ch in s2:s2_[ch] = s2_.get(ch, 0) + 1return s1_ == s2_
