Skip to content

Commit 7617104

Browse files
authored
Merge pull request gzc426#7 from gityjx/gityjx-patch-5
Create halfofwater.md
2 parents da01a07 + fcd26a0 commit 7617104

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2018.12.1-leetcode387/halfofwater.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Leetcode 387
2+
3+
``` C++
4+
class Solution {
5+
public:
6+
int firstUniqChar(string s) {
7+
if (s.size() == 0) return -1;
8+
if (s.size() < 2) return 0;
9+
string alphabet = "abcdefghijklmnopqrstuvwxyz";
10+
map<char, int> countMap;
11+
s += '\0';
12+
char *sHead = (char *)s.data();
13+
char *head = sHead;
14+
while (*sHead != '\0')
15+
{
16+
countMap[*sHead]++;
17+
++sHead;
18+
}
19+
for (int i = 0; i < s.size(); i++) {
20+
if (countMap[s[i]] == 1){
21+
return i;
22+
}
23+
}
24+
return -1;
25+
}
26+
};
27+
```

0 commit comments

Comments
 (0)