python算法-1字符串-2判断是否同一个字符串

python算法-1字符串-2判断是否同一个字符串

python算法-1字符串-2判断是否同一个字符串

 

在线运行:https://pyleetcode.gitee.io/codes_html/SYL_1%E5%AD%97%E7%AC%A6%E4%B8%B2_2%E6%98%AF%E5%90%A6%E5%90%8C%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2.html

import collections


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


class Solution2:

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


if __name__ == '__main__':
    # 字符串忽略顺序,是否为同一个
    s2 = Solution2()
    a2 = s2.anagram('abcdeee', 'eeeadcb')
    print(a2)

 

你可能感兴趣的:(算法LeetCode)