给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换。
置换的意思是,通过改变顺序可以使得两个字符串相等。
思路:将字符串排序后比较
class Solution:
"""
@param A: a string
@param B: a string
@return: a boolean
"""
def Permutation(self, A, B):
# write your code here
list1 = [ i for i in A]
list2 = [ i for i in B]
list1.sort()
list2.sort()
if list1 == list2:
print("list1 is equal to list2")
return True
print(list1)
print(list2)
return False
来源:https://www.cnblogs.com/maybug/p/12386360.html