Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions C++/Crawler-Log-Folder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int minOperations(vector<string>& logs) {
stack<string> s; //stack s is initialized and stack is empty when you are on main folder
for(int i=0;i<logs.size();i++){
if (logs[i]=="../" && !s.empty()){ //if string is "../" and stack is not empty then go back one folder
s.pop();
}
else if((logs[i]=="./") || (logs[i]=="../" && s.empty())) { //if string is "./" or stack is empty and string is "../" then do nothing
continue;
}
else { // otherwise push the new folder on top of stack
s.push(logs[i]);
}
}
return s.size(); //number of steps required to go back to main folder will be equal to the number of elements remaining in the stack
}
};
35 changes: 35 additions & 0 deletions Java/Design-a-Stack-With-Increment-Operation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class CustomStack {
int[] stack;
public int top=-1;
public CustomStack(int maxSize) {
stack=new int[maxSize];
}

public void push(int x) {
if(top<stack.length-1)
{
stack[++top]=x;
}
}

public int pop() {
if(top==-1)
return -1;
top--;
return stack[top+1];
}

public void increment(int k, int val) {
for(int i=0;i<(k>top+1?top+1:k);i++) {
stack[i]+=val;
}
}
}

/**
* Your CustomStack object will be instantiated and called as such:
* CustomStack obj = new CustomStack(maxSize);
* obj.push(x);
* int param_2 = obj.pop();
* obj.increment(k,val);
*/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./Python/150.EvaluateReversePolishNotation.py) | _O(n)_ | _O(1)_ | Medium | Stack | |
| 1047 | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [C++](./C++/remove-all-adjacent-duplicates-in-string.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |
| 682 | [Baseball Game](https://leetcode.com/problems/baseball-game/) | [C++](./C++/Baseball-Game.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |
| 1381 | [Design a Stack With Increment Operation](https://leetcode.com/problems/design-a-stack-with-increment-operation/) | [Java](./Java/Design-a-Stack-With-Increment-Operation.java) | _O(n)_ | _O(n)_ | Medium | Stack | |
| 1598 | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [C++](./C++/Crawler-Log-Folder.cpp) | _O(n)_ | _O(n)_ | Easy | Stack | |

<br/>
<div align="right">
Expand Down