# 暴力循环
class Solution:
def CheckPermutation(self, s1: str, s2: str) -> bool:
if len(s1) != len(s2):
return False
for i in range(len(s1)):
if s1[i] not in s2:
return False
for j in range(len(s2)):
if s1[i] == s2[j]:
s2 = s2[:j] + s2[j + 1:]
break
return True
# 哈希表
class Solution:
def CheckPermutation(self, s1: str, s2: str) -> bool:
s_dict = {}
for i in s1:
if i not in s_dict:
s_dict[i] = 1
else:
s_dict[i] += 1
for j in s2:
if j not in s_dict:
s_dict[j] = -1
else:
s_dict[j] -= 1
if s_dict[j] < 0:
return False
return True