LeetCode题解(面试01.04):判断字符串是否为可转换为回文排列(Python)

阅读 144

2022-02-23


题目:​​原题链接​​(简单)

标签:字符串、哈希表

解法

时间复杂度

空间复杂度

执行用时

Ans 1 (Python)

O ( N )

O ( N )

40ms (67.47%)

Ans 2 (Python)

Ans 3 (Python)

解法一:

class Solution:
def canPermutePalindrome(self, s: str) -> bool:
lst = set()
for ch in s:
if ch not in lst:
lst.add(ch)
else:
lst.remove(ch)
return len(lst) <= 1



相关推荐

精彩评论(0)

0 0 举报