File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 46
46
1189|[ Maximum Number of Balloons] ( ./1189-maximum-number-of-balloons.js ) |Easy|
47
47
1207|[ Unique Number of Occurrences] ( ./1207-unique-number-of-occurrences.js ) |Easy|
48
48
1232|[ Check If It Is a Straight Line] ( ./1232-check-if-it-is-a-straight-line.js ) |Easy|
49
+ 1233|[ Remove Sub-Folders from the Filesystem] ( ./1233-remove-sub-folders-from-the-filesystem.js ) |Medium|
49
50
1249|[ Minimum Remove to Make Valid Parentheses] ( ./1249-minimum-remove-to-make-valid-parentheses.js ) |Medium|
50
51
1252|[ Cells with Odd Values in a Matrix] ( ./1252-cells-with-odd-values-in-a-matrix.js ) |Easy|
51
52
1287|[ Element Appearing More Than 25% In Sorted Array] ( ./1287-element-appearing-more-than-25-in-sorted-array.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1233. Remove Sub-Folders from the Filesystem
3
+ * https://leetcode.com/problems/remove-sub-folders-from-the-filesystem/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a list of folders, remove all sub-folders in those folders
7
+ * and return in any order the folders after removing.
8
+ *
9
+ * If a folder[i] is located within another folder[j], it is called
10
+ * a sub-folder of it. The format of a path is one or more concatenated
11
+ * strings of the form: / followed by one or more lowercase English
12
+ * letters. For example, /leetcode and /leetcode/problems are valid
13
+ * paths while an empty string and / are not.
14
+ */
15
+
16
+ /**
17
+ * @param {string[] } folder
18
+ * @return {string[] }
19
+ */
20
+ var removeSubfolders = function ( folder ) {
21
+ const set = new Set ( folder ) ;
22
+ return folder . filter ( path => ! getPathSegments ( path ) . some ( p => set . has ( p ) ) ) ;
23
+ } ;
24
+
25
+ function getPathSegments ( path ) {
26
+ const split = path . split ( '/' ) ;
27
+ const segments = [ split . shift ( ) ] ;
28
+ while ( split . length > 1 ) {
29
+ segments . push ( segments [ segments . length - 1 ] + '/' + split . shift ( ) ) ;
30
+ }
31
+ return segments ;
32
+ }
You can’t perform that action at this time.
0 commit comments