您的位置:首页 > 产品设计 > UI/UE

LeetCode-First Unique Character in a String

2016-09-13 19:31 585 查看
题目:

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.
题目意思时给你一个字符串,找出第一个没有在字符串重复出现的的字符的下标索引号;

解题思路:先用hashmap把字符串中每一个字符存储到hashmap中,把字符串重复数存储到key所对应的value中,然后再遍历hashmap,找第一个value等于1的数值对,返回其下标索引即可;

代码如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LeetCode