Leetcode 面试题 01.01. 判定字符是否唯一 (每日一题 20211012)
生活随笔
收集整理的這篇文章主要介紹了
Leetcode 面试题 01.01. 判定字符是否唯一 (每日一题 20211012)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
實現一個算法,確定一個字符串 s 的所有字符是否全都不同。示例 1:輸入: s = "leetcode"
輸出: false
示例 2:輸入: s = "abc"
輸出: true限制:0 <= len(s) <= 100
如果你不使用額外的數據結構,會很加分。鏈接:https://leetcode-cn.com/problems/is-unique-lcciclass Solution:def isUnique(self, astr: str) -> bool:# dd = {}# for cc in astr:# if cc in dd:# return False# else:# dd[cc] = 1# return True# return len(astr) == len(set(astr))if len(astr) != 0:ll = len(astr) - 1for cc in astr:if len(astr.replace(cc,'')) != ll:return Falsereturn True
總結
以上是生活随笔為你收集整理的Leetcode 面试题 01.01. 判定字符是否唯一 (每日一题 20211012)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 18. 四数之和 (每
- 下一篇: Leetcode 91. 解码方法 (每