Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/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 =…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.com/problems/first-unique-character-in-a-string/description/ 题目描述 Given a string, find the first non-repeating character in it and return it's index. I…
#-*- coding: UTF-8 -*- class Solution(object):    def firstUniqChar(self, s):        s=s.lower()        sList=list(s)        numCdic={}        for c in s:            numCdic[c]=numCdic[c]+1 if c in numCdic else 1        for i in range(len(sList)):   …
-------------------------------------------------- 最开始的想法是统计每个字符的出现次数和位置,如下: AC代码: public class Solution { public int firstUniqChar(String s) { Count c[]=new Count[26]; for(int i=0;i<s.length();i++){ int index=s.charAt(i)-'a'; if(c[index]==null) c[in…
这是悦乐书的第213次更新,第226篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第81题(顺位题号是387).给定一个字符串,找到它中的第一个非重复字符并返回它的索引. 如果它不存在,则返回-1.例如: 输入:"leetcode" 输出:0 输入:"loveleetcode", 输出:2 注意:您可以假设该字符串仅包含小写字母. 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/ 题目描述 Given a string S of lowercase letters, a duplicate removal consists of choosing two adjac…
题目标签:String, HashMap 题目给了我们一个 string,让我们找出 第一个 唯一的 char. 设立一个 hashmap,把 char 当作 key,char 的index 当作value. 遍历string,如果这个 char 没有在 map 里,说明第一次出现,存入 char,index:                    如果这个 char 已经在 map 里,说明不是第一次出现,而且我们不在乎这种情况,更新 char, -1. 遍历hashmap,把最小的 inde…
Problem: Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Example: s = "leetcode" return 0. s = "loveleetcode", return 2. 本题的第一想法是开一个字母表计数器,遍历string s中的元素,并利用计数器对每一个字母计…
最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. leetcode的题目如下: 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: Y…
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 lowerca…