首页 > 其他 > 详细

71. Simplify Path

时间:2020-02-12 21:25:43      阅读:54      评论:0      收藏:0      [点我收藏+]

Problem:

思路

Solution (C++):

string simplifyPath(string path) {
    string res, tmp;
    vector<string> my_stack;
    stringstream ss(path);
    while (getline(ss, tmp, '/')) {
        if (tmp == "" || tmp == ".")  continue;
        if (tmp == ".." && !my_stack.empty())  my_stack.pop_back();
        else if (tmp != "..")  my_stack.push_back(tmp);
    }
    for (auto str: my_stack) res += "/" + str;
    return res.empty() ? "/" : res;
}

性能

Runtime: 8 ms??Memory Usage: 10.4 MB

71. Simplify Path

原文:https://www.cnblogs.com/dysjtu1995/p/12300252.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!