Warm Up Contest
class Solution {
public:
vector<int> lexicalOrder(int n) {
vector<int> res;
map<string, int> hm;
for(int i = 1; i <= n; i++) {
hm[to_string(i)] = i;
}
for(auto iter = hm.begin(); iter != hm.end(); iter++) {
res.push_back(iter->second);
}
return res;
}
};
class Solution {
public:
int firstUniqChar(string s) {
unordered_map<char,int> hm;
for(auto c : s) hm[c]++;
for(int i = 0; i < s.size(); i++) {
if(hm[s[i]] == 1) return i;
}
return -1;
}
};
class Solution {
public:
int lengthLongestPath(string input) {
stack<int> stk;
int res = 0;
for(int i = 0, sum = 0; i < input.size(); ) {
int k = 0;
while(i < input.size() && input[i] == '\t') i++, k++;
while(stk.size() > k) sum -= stk.top(), stk.pop();
int j = i;
while(j < input.size() && input[j] != '\n') j++;
int len = j - i;
stk.push(len), sum += len;
if(input.substr(i, len).find('.') != -1)
res = max(res, sum+(int)stk.size()-1);
i = j;
}
return res;
}
}