Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
393 posts
14 categories
117 tags

LeetCode 387. First Unique Character in a String

Posted on 2020-12-23 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
int firstUniqChar(string s) {
unordered_map<int, int> frequency;
for (char ch: s)
++frequency[ch];
for (int i = 0; i < s.size(); ++i)
if (frequency[s[i]] == 1)
return i;
return -1;
}
};
# Hash Table# String
LeetCode 134. Gas Station
LeetCode 135. Candy
© 2026 Shawn
Powered by Hexo & NexT.Mist
0%