1.(字符串)-判断两字符串是否相等

Python:

通过collections的Counter类统计字典,转为判断字典是否相等 

import collections


class Solution:
    """
    @param s: The first string
    @param b: The second string
    @return true or false
    """

    def anagram(self, s, t):
        cs = collections.Counter(s)
        ct = collections.Counter(t)
        return cs == ct

s = Solution()
a = s.anagram('abcdeee', 'eeeadcb')
print(a)

通过字符串排序,转为判断字符串是否相等 

class Solution2:

    def anagram(self, s, t):
        return sorted(s) == sorted(t)

s2=Solution2()
a2=s2.anagram('abcdeee', 'eeeadcb')
print(a2)
原文地址:https://www.cnblogs.com/onenoteone/p/12441792.html