We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5f4f024 commit 0ae5426Copy full SHA for 0ae5426
javascript/0071-simplify-path.js
@@ -0,0 +1,33 @@
1
+/**
2
+ * Stack
3
+ * https://leetcode.com/problems/simplify-path/
4
+ *
5
+ * Time O(n) | Space O(n)
6
+ * @param {string} path
7
+ * @return {string}
8
+ */
9
+var simplifyPath = function(path) {
10
+ let currunt = '';
11
+ let myStack = [];
12
+ path = '/' + path + '/';
13
+ for(let i = 0; i < path.length; i++) {
14
+
15
+ console.log(myStack);
16
+ if(path[i] === '/') {
17
+ if(currunt == '..') {
18
+ if(myStack.length) {
19
+ myStack.pop();
20
+ }
21
+ } else if(currunt !== '' && currunt !== '.') {
22
+ myStack.push(currunt);
23
24
+ currunt = '';
25
+ } else {
26
+ currunt += path[i];
27
28
29
30
+ myStack = myStack.join('/');
31
+ myStack = '/' + myStack;
32
+ return myStack;
33
+};
0 commit comments