题解 | #判断字符是否唯一#
判断字符是否唯一
http://www.nowcoder.com/practice/fb08c63e2c4f4f7dbf41086e46044211
调用 collections.Counter 对 字符串进行计数,然后统计 count 中是否有不为 1 的字符
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param str string字符串
# @return bool布尔型
#
from collections import Counter
class Solution:
def isUnique(self , s: str) -> bool:
# write code here
count = Counter(s)
for k, v in count.items():
if v != 1:
return False
return True
题解 文章被收录于专栏
算法题解
三奇智元机器人科技有限公司公司福利 70人发布
