Posted on

Description

Submission

class Solution {
public:
    int minOperations(vector<string>& logs) {
        stack<string> stk;
        
        for(string& l: logs) {
            if(l == "./") {
                continue;
            } else if(l == "../") {
                if(!stk.empty()) stk.pop();
            } else {
                stk.push(l);
            }
        }
        
        int res = 0;
        while(!stk.empty()) {
            res++;
            stk.pop();
        }
        return res;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *