0
点赞
收藏
分享

微信扫一扫

LeetCode题解(1657):确定两个字符串是否接近(Python)


题目:​​原题链接​​(中等)

标签:贪心算法、字符串

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

O ( N 1 + N 2 )

O ( N 1 + N 2 )

172ms (57.34%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def closeStrings(self, word1: str, word2: str) -> bool:
count1, count2 = Counter(word1), Counter(word2)
return (len(word1) == len(word2) and
set(count1.keys()) == set(count2.keys()) and
set(count1.values()) == set(count2.values()))



举报

相关推荐

0 条评论