标签:sum break mic let class family c99 ase string
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 = "loveleetcode", return 2.
Note: You may assume the string contain only lowercase letters.
代码:
class Solution { public: int firstUniqChar(string s) { int len = s.length(); unordered_map<char, int> mp; int ans = -1; for(int i = 0; i < len; i ++) mp[s[i]] ++; for(int i = 0; i < len; i ++) { if(mp[s[i]] == 1) { ans = i; break; } } return ans; } };
FHFHFH
#Leetcode# 387. First Unique Character in a String
标签:sum break mic let class family c99 ase string
原文地址:https://www.cnblogs.com/zlrrrr/p/10339719.html