最近公司搬家了,有两天没写了,今天闲下来了,继续开始算法之路. 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…
题目标签: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中的元素,并利用计数器对每一个字母计…
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…
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…
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…
题目描述: 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个数的数组,然后先对字符串过一遍,统计每个字母出现的次数,然后从头再国一遍,…
The ability to debug and overall thinking need to improve 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…
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 =…
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…
作者: 负雪明烛 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…
-------------------------------------------------- 最开始的想法是统计每个字符的出现次数和位置,如下: 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…
#-*- 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)):   …
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. 分析:找出字符串中第一次出现且不重复的字符,返回其字符的下标,如果不存在就返回-1. 用hashMap进行求…
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…
题目描述 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 lowe…
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1.案例:s = "leetcode"返回 0.s = "loveleetcode",返回 2.注意事项:您可以假定该字符串只包含小写字母.详见:https://leetcode.com/problems/first-unique-character-in-a-string/description/ C++: class Solution { public: int firstUniq…
387. First Unique Character in a String Easy 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…
Description Find the first unique character in a given string. You can assume that there is at least one unique character in the string. Example For "abaccdeff", return 'b'. 解题:返回仅出现一次,并且排在最前面的那个元素,而不是返回第一个不同的元素,一开始理解错了.如果仅仅对于ASCII中的256个字符,可以用数组…
题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -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. 注意事项:您可以假定该字符串只包含小写字…
这是悦乐书的第213次更新,第226篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第81题(顺位题号是387).给定一个字符串,找到它中的第一个非重复字符并返回它的索引. 如果它不存在,则返回-1.例如: 输入:"leetcode" 输出:0 输入:"loveleetcode", 输出:2 注意:您可以假设该字符串仅包含小写字母. 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java…
问题描述 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. Java算法实现 public class Solution { public int first…
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…
原题链接在这里: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 = "leetcode" return 0. s = "lovele…
题目描述: 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 low…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3939 访问. 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1. s = "leetcode",返回 0. s = "loveleetcode",返回 2. 注意事项:您可以假定该字符串只包含小写字母. Given a string, find the first non-repeating ch…
哈哈,我又来了.昨天发现题目太简单就没有放上来,今天来了一道有序链表的题.题目如下: Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 题目分析:简单来说就是去除有序链…
题目: Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 题目分析: 将罗马数字转换成阿拉伯数字,规则如下:罗马数字共有七个,即I(1),V(5),X(10),L(50),C(100),D(500),M(1000). 按照下面的规则可以表示任意正整数. 重复数次:一个罗马数字重复几次,就表示这个数的几倍.右加左减:在一个较大的罗马数…
题目如下: Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many times as it shows in both arrays. The result can be in…
题目是这样的 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransom 
 note 
can 
be 
constructed 
from 
the 
magazines ; 
otherwise, 
i…