Re: [闲聊] 每日LeetCode

楼主: JerryChungYC (JerryChung)   2024-02-05 08:52:12
https://leetcode.com/problems/first-unique-character-in-a-string
387. First Unique Character in a String
给一个字串s,找到第一个不重复的字符回传其索引,不存在则回传-1
Example 1:
Input: s = "leetcode"
Output: 0
Example 2:
Input: s = "loveleetcode"
Outpue: 2
Example 3:
Input: s = "aabb"
Output: -1
思路:
用for循环找出只出现一次的字符
Python3 code:
作者: JIWP (JIWP)   2024-02-05 08:58:00
大师
作者: PyTorch (屁眼火炬)   2024-02-05 09:01:00
大师
作者: wu10200512 (廷廷)   2024-02-05 09:01:00
这不是哈希表ㄇ
楼主: JerryChungYC (JerryChung)   2024-02-05 09:04:00
那就自己建 counter = {} :(counter = defaultdict(int)for i in s:counter[i] += 1

Links booklink

Contact Us: admin [ a t ] ucptt.com