Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note: You may assume the string contain only lowercase letters. 给一个字符串,找出第一个不重复的...
class Solution: def firstUniqChar(self, s: str) -> int: dic = {} for i in range(len(s)): if s[i] not in dic: dic[s[i]] = [1, i] else: dic[s[i]][0] += 1 rat = len(s) for key in dic.keys(): if dic[key][0] == 1: rat = min(rat, dic[key][1]) if ...
First Unique Character in a String 387. First Unique Character in a String Easy Given a string, find the first non-repeating character ... 209. First Unique Character in a String Description Find the first unique character in a given string. You can assume that there is at least ......
leetcode 每日一题:387. 字符串中的第一个唯一字符:https://leetcode-cn.com/problems/first-unique-character-in-a-string/ 一起刷题吧 一、题目分析 输入:字符串 输出:第一个不重复的元素的下标 难度:简单 标签:哈希表,字符串 示例: s = "leetcode" 返回0 s = "loveleetcode" 返回2 二、参考代码 ...
leetcode 387. First Unique Character in a String Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: s = “leetcode” return 0. s = “loveleetcode”,...
字符串中的第一个唯一字符(first unique character in a string)-java 字符串中的第一个唯一字符 first unique character in a string 题目 分析 解答 题目 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 案例: 代码模板: 分析 循环这个数组,如果firstindexOf和last...
LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String 题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1....
字符串中的第一个唯一字符 题目描述:给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。示例说明请见LeetCode官网。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/first-unique-character-in-a-string/著作权归领扣网络所有。商业转载请联系官方授权,非商业...
Examples:s = "leetcode" return 0. s = "loveleetcode", return 2.解题思路: class Solution: def firstUniqChar(self, s: str) -> int: hashtable = {} for idx, i in enumerate(s): if i n…
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. 解题思路: 开个26个数的数组,然后先对字符串过一遍,统计每个字母出现的次数,然后从头再国一遍,第一个...