Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3cfb9a5 commit df650d6Copy full SHA for df650d6
javascript/71-simplify-path.js
@@ -0,0 +1,27 @@
1
+// problem link https://leetcode.com/problems/simplify-path
2
+// time complexity O(n)
3
+
4
+var simplifyPath = function(path) {
5
+ let currunt = '';
6
+ let myStack = [];
7
+ path = '/' + path + '/';
8
+ for(let i = 0; i < path.length; i++) {
9
10
+ if(path[i] === '/') {
11
+ if(currunt == '..') {
12
+ if(myStack.length) {
13
+ myStack.pop();
14
+ }
15
+ } else if(currunt !== '' && currunt !== '.') {
16
+ myStack.push(currunt);
17
18
+ currunt = '';
19
+ } else {
20
+ currunt += path[i];
21
22
23
24
+ myStack = myStack.join('/');
25
+ myStack = '/' + myStack;
26
+ return myStack;
27
+};
0 commit comments