lintcode入门篇七

211. 字符串置换

给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换。

置换的意思是,通过改变顺序可以使得两个字符串相等。

样例

Example 1:
	Input:  "abcd", "bcad"
	Output:  True


Example 2:
	Input: "aac", "abc"
	Output:  False
class Solution:
    """
    @param A: a string
    @param B: a string
    @return: a boolean
    """
    def Permutation(self, A, B):
        # write your code here
        dic_A,dic_B = {},{}
        for i in A:
            dic_A[i] = dic_A.get(i,0)+1##每次循环,相同字符的值加1,初始值为0
        for j in B:
            dic_B[j] = dic_B.get(j,0)+1
        return dic_A == dic_B

猜你喜欢

转载自www.cnblogs.com/yunxintryyoubest/p/12417177.html