回答編集履歴
1
追記
test
CHANGED
@@ -39,3 +39,57 @@
|
|
39
39
|
};
|
40
40
|
|
41
41
|
```
|
42
|
+
|
43
|
+
[つけたし] ハッシュ表使うまでもないか...
|
44
|
+
|
45
|
+
```C++
|
46
|
+
|
47
|
+
#include <string>
|
48
|
+
|
49
|
+
#include <algorithm>
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
class Solution {
|
54
|
+
|
55
|
+
public:
|
56
|
+
|
57
|
+
int firstUniqChar(const std::string& s) {
|
58
|
+
|
59
|
+
int hist[256];
|
60
|
+
|
61
|
+
std::fill(hist, hist+256, 0);
|
62
|
+
|
63
|
+
for ( char ch : s ) {
|
64
|
+
|
65
|
+
hist[ch]++;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
for ( int i = 0; i < s.size(); ++i ) {
|
70
|
+
|
71
|
+
if ( hist[s.at(i)] == 1 ) return i;
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
return -1;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
};
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
#include <iostream>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
int main() {
|
88
|
+
|
89
|
+
Solution s;
|
90
|
+
|
91
|
+
std::cout << s.firstUniqChar("abcdefghijkld") << std::endl;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
```
|