Skip to content

Commit ce92985

Browse files
committed
1166 updated.
1 parent 5d28eb6 commit ce92985

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

1001-1500/1166-Design-File-System/cpp-1166/main.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Source : https://leetcode.com/problems/design-file-system/
22
/// Author : liuyubobobo
33
/// Time : 2019-08-24
4+
/// Updated: 2022-04-21
45

56
#include <iostream>
67
#include <unordered_set>
@@ -11,8 +12,8 @@ using namespace std;
1112

1213

1314
/// Using HashMap
14-
/// Time Complexity: create: O(|path|)
15-
/// get: O(1)
15+
/// Time Complexity: createPath: O(|path|)
16+
/// get: O(|path|)
1617
/// Space Complexity: O(|query| * |path|)
1718
class FileSystem {
1819

@@ -24,7 +25,9 @@ class FileSystem {
2425
map[""] = -1;
2526
}
2627

27-
bool create(string path, int value) {
28+
bool createPath(string path, int value) {
29+
30+
if(map.count(path)) return false;
2831

2932
int last = path.rfind('/');
3033
if(!map.count(path.substr(0, last))) return false;
@@ -42,10 +45,10 @@ class FileSystem {
4245
int main() {
4346

4447
FileSystem fs;
45-
cout << fs.create("/leet", 1) << endl;
46-
cout << fs.create("/leet/code", 2) << endl;
48+
cout << fs.createPath("/leet", 1) << endl;
49+
cout << fs.createPath("/leet/code", 2) << endl;
4750
cout << fs.get("/leet/code") << endl;
48-
cout << fs.create("/c/d", 1) << endl; // false
51+
cout << fs.createPath("/c/d", 1) << endl; // false
4952
cout << fs.get("/c") << endl; // -1
5053

5154
return 0;

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
533533
| | | | | | |
534534
| 509 | [Fibonacci Number](https://leetcode.com/problems/fibonacci-number/) | [] | [C++](0501-1000/0509-Fibonacci-Number/cpp-0509/) | | |
535535
| | | | | | |
536+
| 511 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
537+
| | | | | | |
536538
| 516 | [Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) | [] | [C++](0501-1000/0516-Longest-Palindromic-Subsequence/cpp-0516/) | | |
537539
| 517 | [Super Washing Machines](https://leetcode.com/problems/super-washing-machines/) | [solution](https://leetcode.com/problems/super-washing-machines/solution/) | [C++](0501-1000/0517-Super-Washing-Machines/cpp-0517/) | | |
538540
| 518 | [Coin Change 2](https://leetcode.com/problems/coin-change-2/description/) | [] | [C++](0501-1000/0518-Coin-Change-2/cpp-0518/) | | |
@@ -595,6 +597,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
595597
| 583 | [Delete Operation for Two Strings](https://leetcode.com/problems/delete-operation-for-two-strings/description/) | [solution](https://leetcode.com/problems/delete-operation-for-two-strings/solution/) | [C++](0501-1000/0583-Delete-Operation-for-Two-Strings/cpp-0583/) | | |
596598
| 584 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
597599
| | | | | | |
600+
| 586 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
598601
| 587 | [Erect the Fence](https://leetcode.com/problems/erect-the-fence/) | [solution](https://leetcode.com/problems/erect-the-fence/solution/) [题解](https://leetcode-cn.com/problems/erect-the-fence/solution/an-zhuang-zha-lan-by-leetcode/)<br/>[缺:凸包解法整理] | [C++](0501-1000/0587-Erect-the-Fence/cpp-0587/) | | |
599602
| | | | | | |
600603
| 589 | [N-ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal/) | [solution](https://leetcode.com/problems/n-ary-tree-preorder-traversal/solution/) | [C++](0501-1000/0589-N-ary-Tree-Preorder-Traversal/cpp-0589/) | | |
@@ -1074,6 +1077,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
10741077
| 1138 | [Alphabet Board Path](https://leetcode.com/problems/alphabet-board-path/) | [] | [C++](1001-1500/1138-Alphabet-Board-Path/cpp-1138/) | | |
10751078
| 1139 | [Largest 1-Bordered Square](https://leetcode.com/problems/largest-1-bordered-square/) | [] | [C++](1001-1500/1139-Largest-1-Bordered-Square/cpp-1139/) | | |
10761079
| 1140 | [Stone Game II](https://leetcode.com/problems/stone-game-ii/) | [] | [C++](1001-1500/1140-Stone-Game-II/cpp-1140/) | | |
1080+
| 1141 | Database Problem: [Link](https://github.com/liuyubobobo/Play-Leetcode-Database/) | - | - | - | - |
10771081
| | | | | | |
10781082
| 1143 | [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/) | [] | [C++](1001-1500/1143-Longest-Common-Subsequence/cpp-1143/) | | |
10791083
| 1144 | [Decrease Elements To Make Array Zigzag](https://leetcode.com/problems/decrease-elements-to-make-array-zigzag/) | [] | [C++](1001-1500/1144-Decrease-Elements-To-Make-Array-Zigzag/cpp-1144/) | | |

0 commit comments

Comments
 (0)