8000 2 · hitzzc/go-leetcode@3a54877 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a54877

Browse files
committed
2
1 parent 898e468 commit 3a54877

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
264264
#### [383. Ransom Note](https://github.com/hitzzc/go-leetcode/tree/master/ransom_note)
265265
#### [384. Shuffle an Array](https://github.com/hitzzc/go-leetcode/tree/master/shuffle_an_array)
266266
#### [386. Lexicographical Numbers](https://github.com/hitzzc/go-leetcode/tree/master/lexicographical_numbers)
267+
#### [387. First Unique Character in a String](https://github.com/hitzzc/go-leetcode/tree/master/first_unique_character_in_a_string)
268+
#### [388. Longest Absolute File Path](https://github.com/hitzzc/go-leetcode/tree/master/longest_absolute_file_path)
269+
267270

268271

269272

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int firstUniqChar(string s) {
4+
unordered_map<char, int> m;
5+
for (auto& ch: s) {
6+
++m[ch];
7+
}
8+
for (int i = 0; i < s.size(); ++i) {
9+
if (m[s[i]] == 1) return i;
10+
}
11+
return -1;
12+
}
13+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
int lengthLongestPath(string input) {
4+
unordered_map<int, int> depth;
5+
int level = 0, res = 0;
6+
for (int i = 0; i < input.size(); ++i) {
7+
int start = i;
8+
while (i < input.size() && input[i] != '\n' && input[i] != '\t') ++i;
9+
if (i == input.size() || input[i] == '\n') {
10+
string name = input.substr(start, i-start);
11+
if (name.find('.') != string::npos) {
12+
res = max(res, depth[level] + (int)name.size());
13+
}else {
14+
++level;
15+
depth[level] = depth[level-1] + (int)name.size() + 1;
16+
}
17+
level = 0;
18+
}else {
19+
++level;
20+
}
21+
}
22+
return res;
23+
}
24+
};

0 commit comments

Comments
 (0)
2A32
0