String Permutation

来源:互联网 发布:福州锐掌网络怎么样 编辑:程序博客网 时间:2024/06/06 19:19

Given two strings, write a method to decide if one is a permutation of the other.

python
class Solution:    """    @param: A: a string    @param: B: a string    @return: a boolean    """    def Permutation(self, A, B):        # write your code here        if A is None and B is not None:            return False        if A is not None and B is None:            return False        if A is None and B is None:            return True        if len(A) != len(B):            return False        arr = [0] * 256        for ele in list(A):            arr[ord(ele)] += 1        for val in list(B):            arr[ord(val)] -= 1            if arr[ord(val)] < 0:                return False        return True


原创粉丝点击