classSolution { public: intlengthLongestPath(string input){ if (input.empty()) return0; int res = 0; stack<string> s; input += '\n'; int b = 0, e = input.find('\n'), lvl = 0, len = 0; for (; e != string::npos; e = input.find('\n', b)) { while (s.size() > lvl) { len -= s.top().length(); s.pop(); } s.push(input.substr(b, e - b + 1)); len += s.top().length(); if (s.top().find('.') != string::npos) { res = max(res, len - 1); } for (b = e + 1, lvl = 0; b < input.length() && input[b] == '\t'; ++b, ++lvl); } return res; } };