Skip to content

Commit 0e21c32

Browse files
committedJan 24, 2020
Add solution #1233
1 parent c9fa5c7 commit 0e21c32

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
1189|[Maximum Number of Balloons](./1189-maximum-number-of-balloons.js)|Easy|
4747
1207|[Unique Number of Occurrences](./1207-unique-number-of-occurrences.js)|Easy|
4848
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|
4950
1249|[Minimum Remove to Make Valid Parentheses](./1249-minimum-remove-to-make-valid-parentheses.js)|Medium|
5051
1252|[Cells with Odd Values in a Matrix](./1252-cells-with-odd-values-in-a-matrix.js)|Easy|
5152
1287|[Element Appearing More Than 25% In Sorted Array](./1287-element-appearing-more-than-25-in-sorted-array.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.