LeetCode-First Unique Character in a String

来源:互联网 发布:太原网络规划研究院 编辑:程序博客网 时间:2024/04/28 22:34

题目:

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的数值对,返回其下标索引即可;


代码如下:


0 0
原创粉丝点击