File tree 3 files changed +68
-0
lines changed
3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 194
194
| 1002| [ 查找共用字符] ( https://leetcode.cn/problems/find-common-characters/ ) | [ JavaScript] ( ./algorithms/find-common-characters.js ) | Easy|
195
195
| 1038| [ 从二叉搜索树到更大和树] ( https://leetcode.cn/problems/binary-search-tree-to-greater-sum-tree/ ) | [ JavaScript] ( ./algorithms/binary-search-tree-to-greater-sum-tree.js ) | Medium|
196
196
| 1047| [ 删除字符串中的所有相邻重复项] ( https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/ ) | [ JavaScript] ( ./algorithms/remove-all-adjacent-duplicates-in-string.js ) | Easy|
197
+ | 1233| [ 删除子文件夹] ( https://leetcode.cn/problems/remove-sub-folders-from-the-filesystem/ ) | [ JavaScript] ( ./algorithms/remove-sub-folders-from-the-filesystem.js ) | Medium|
197
198
| 1413| [ 逐步求和得到正数的最小值] ( https://leetcode.cn/problems/minimum-value-to-get-positive-step-by-step-sum/ ) | [ JavaScript] ( ./algorithms/minimum-value-to-get-positive-step-by-step-sum.js ) | Easy|
198
199
| 1604| [ 警告一小时内使用相同员工卡大于等于三次的人] ( https://leetcode.cn/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/ ) | [ JavaScript] ( ./algorithms/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period.js ) | Medium|
199
200
| 1664| [ 生成平衡数组的方案数] ( https://leetcode.cn/problems/ways-to-make-a-fair-array/ ) | [ JavaScript] ( ./algorithms/ways-to-make-a-fair-array.js ) | Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * [1233] 删除子文件夹
3
+ * @param {string[] } folder
4
+ * @return {string[] }
5
+ */
6
+ var removeSubfolders = function ( folder ) {
7
+ folder . sort ( ) ;
8
+ set = new Set ( ) ;
9
+ const result = [ ] ;
10
+
11
+ for ( let i = 0 ; i < folder . length - 1 ; i ++ ) {
12
+ for ( let j = i + 1 ; j < folder . length ; j ++ ) {
13
+ if ( isSub ( folder [ i ] , folder [ j ] ) ) {
14
+ set . add ( j ) ;
15
+ } else {
16
+ break ;
17
+ }
18
+ }
19
+ }
20
+ for ( let i = 0 ; i < folder . length ; i ++ ) {
21
+ if ( ! set . has ( i ) ) {
22
+ result . push ( folder [ i ] ) ;
23
+ }
24
+ }
25
+ return result ;
26
+ } ;
27
+ function isSub ( parent , child ) {
28
+ return child . startsWith ( parent + '/' ) ;
29
+ }
30
+
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @lc app=leetcode.cn id=1233 lang=javascript
3
+ *
4
+ * [1233] 删除子文件夹
5
+ */
6
+
7
+ // @lc code=start
8
+ /**
9
+ * @param {string[] } folder
10
+ * @return {string[] }
11
+ */
12
+ var removeSubfolders = function ( folder ) {
13
+ folder . sort ( ) ;
14
+ set = new Set ( ) ;
15
+ const result = [ ] ;
16
+
17
+ for ( let i = 0 ; i < folder . length - 1 ; i ++ ) {
18
+ for ( let j = i + 1 ; j < folder . length ; j ++ ) {
19
+ if ( isSub ( folder [ i ] , folder [ j ] ) ) {
20
+ set . add ( j ) ;
21
+ } else {
22
+ break ;
23
+ }
24
+ }
25
+ }
26
+ for ( let i = 0 ; i < folder . length ; i ++ ) {
27
+ if ( ! set . has ( i ) ) {
28
+ result . push ( folder [ i ] ) ;
29
+ }
30
+ }
31
+ return result ;
32
+ } ;
33
+ function isSub ( parent , child ) {
34
+ return child . startsWith ( parent + '/' ) ;
35
+ }
36
+ // @lc code=end
37
+
You can’t perform that action at this time.
0 commit comments