File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 33
33
| 66| [ 加一] ( https://leetcode-cn.com/problems/plus-one/ ) | [ JavaScript] ( ./algorithms/plus-one.js ) | Easy|
34
34
| 69| [ x 的平方根 ] ( https://leetcode.cn/problems/sqrtx/ ) | [ JavaScript] ( ./algorithms/sqrtx.js ) | Easy|
35
35
| 70| [ 爬楼梯] ( https://leetcode.cn/problems/climbing-stairs/ ) | [ JavaScript] ( ./algorithms/climbing-stairs.js ) | Easy|
36
+ | 71| [ 简化路径] ( https://leetcode.cn/problems/simplify-path/ ) | [ JavaScript] ( ./algorithms/simplify-path.js ) | Medium|
36
37
| 73| [ 矩阵置零] ( https://leetcode.cn/problems/set-matrix-zeroes/ ) | [ JavaScript] ( ./algorithms/set-matrix-zeroes.js ) | Medium|
37
38
| 82| [ 删除排序链表中的重复元素 II] ( https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/ ) | [ JavaScript] ( ./algorithms/remove-duplicates-from-sorted-list-ii.js ) | Medium|
38
39
| 83| [ 删除排序链表中的重复元素] ( https://leetcode.cn/problems/remove-duplicates-from-sorted-list/ ) | [ JavaScript] ( ./algorithms/remove-duplicates-from-sorted-list.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } path
3
+ * @return {string }
4
+ */
5
+ var simplifyPath = function ( path ) {
6
+ path = path . split ( "/" ) ;
7
+ let stack = [ ] ;
8
+
9
+ // 忽略 '.' ''
10
+ // 遇到 '..' 则弹出栈顶
11
+
12
+ for ( let char of path ) {
13
+ if ( char === ".." ) {
14
+ stack . pop ( ) ;
15
+ } else if ( char && char !== "." ) {
16
+ stack . push ( char ) ;
17
+ }
18
+ }
19
+
20
+ return `/${ stack . join ( "/" ) } ` ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments