We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题目描述:
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
案例:
s = "leetcode" 返回 0. s = "loveleetcode", 返回 2.
解题思路:遍历一遍用哈希表存好数。第二遍直接返回只出现了一次的字母的下标
C++解法:
class Solution { public: int firstUniqChar(string s) { unordered_map<char,int> map; for(char cc:s){ map[cc]++; } for (int i = 0; i < s.size(); i++) { if(map[s[i]] == 1) return i; } return -1; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目描述:
给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
案例:
解题思路:遍历一遍用哈希表存好数。第二遍直接返回只出现了一次的字母的下标
C++解法:
The text was updated successfully, but these errors were encountered: