给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. class solution: def getChar(self,s): setS = set(s) dict = {} for i in setS: dict[i] = s.count(i) #该方法返回子字符串在字符串中出现的次数. for index,value in enumer
387. 字符串中的第一个唯一字符 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 案例: s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. 注意事项:您可以假定该字符串只包含小写字母. class Solution { public int firstUniqChar(String s) { //fast int n = s.length(); for(int i = 'a'; i
题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. 案例: s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. 注意事项:您可以假定该字符串只包含小写字
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
[问题]给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. s = "leetcode" 返回 . s = "loveleetcode", 返回 . 注意事项:您可以假定该字符串只包含小写字母. [思路]首先建立一个26大小的数组,使用s[i]-'0'作为索引,一次遍历后,使用数组储存每个字符出现的次数.接着再对字符串进行一次遍历,然后根据字符去数组中查找相应的次数,如果第一次出现次数为1,则返回,否则返回-1. class So
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 案例: s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. class Solution(object): def firstUniqChar(self, s): """ :type s: str :rtype: int """ s_len=len(s) for i in &qu
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. 案例: s = "leetcode" 返回 0. s = "loveleetcode", 返回 2. 注意事项:您可以假定该字符串只包含小写字母. /** * @param {string} s * @return {number} */ var firstUniqChar = function (s) { let len = s.length, obj = {}; for (l
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. s = "leetcode",返回 0. s = "loveleetcode",返回 2. 注意事项:您可以假定该字符串只包含小写字母. Given a string, find the first non-repeating ch