You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a string `path`, which is an **absolute path** (starting with a slash `'/'`) to a file or directory in a Unix-style file system, convert it to the simplified **canonical path**.
6
+
7
+
In a Unix-style file system, a period `'.'` refers to the current directory, a double period `'..'` refers to the directory up a level, and any multiple consecutive slashes (i.e. `'//'`) are treated as a single slash `'/'`. For this problem, any other format of periods such as `'...'` are treated as file/directory names.
8
+
9
+
The **canonical path** should have the following format:
10
+
11
+
* The path starts with a single slash `'/'`.
12
+
* Any two directories are separated by a single slash `'/'`.
13
+
* The path does not end with a trailing `'/'`.
14
+
* The path only contains the directories on the path from the root directory to the target file or directory (i.e., no period `'.'` or double period `'..'`)
15
+
16
+
Return _the simplified **canonical path**_.
17
+
18
+
**Example 1:**
19
+
20
+
**Input:** path = "/home/"
21
+
22
+
**Output:** "/home"
23
+
24
+
**Explanation:** Note that there is no trailing slash after the last directory name.
25
+
26
+
**Example 2:**
27
+
28
+
**Input:** path = "/../"
29
+
30
+
**Output:** "/"
31
+
32
+
**Explanation:** Going one level up from the root directory is a no-op, as the root level is the highest level you can go.
33
+
34
+
**Example 3:**
35
+
36
+
**Input:** path = "/home//foo/"
37
+
38
+
**Output:** "/home/foo"
39
+
40
+
**Explanation:** In the canonical path, multiple consecutive slashes are replaced by a single one.
41
+
42
+
**Constraints:**
43
+
44
+
*`1 <= path.length <= 3000`
45
+
*`path` consists of English letters, digits, period `'.'`, slash `'/'` or `'_'`.
Given two integers `n` and `k`, return _all possible combinations of_`k`_numbers chosen from the range_`[1, n]`.
6
+
7
+
You may return the answer in **any order**.
8
+
9
+
**Example 1:**
10
+
11
+
**Input:** n = 4, k = 2
12
+
13
+
**Output:**[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
14
+
15
+
**Explanation:** There are 4 choose 2 = 6 total combinations. Note that combinations are unordered, i.e., [1,2] and [2,1] are considered to be the same combination.
16
+
17
+
**Example 2:**
18
+
19
+
**Input:** n = 1, k = 1
20
+
21
+
**Output:**[[1]]
22
+
23
+
**Explanation:** There is 1 choose 1 = 1 total combination.
Given an integer array `nums` sorted in **non-decreasing order**, remove some duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears **at most twice**. The **relative order** of the elements should be kept the **same**.
6
+
7
+
Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.
8
+
9
+
Return `k`_after placing the final result in the first_`k`_slots of_`nums`.
10
+
11
+
Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.
12
+
13
+
**Custom Judge:**
14
+
15
+
The judge will test your solution with the following code:
16
+
17
+
int[] nums = [...]; // Input array int[] expectedNums = [...]; // The expected answer with correct length int k = removeDuplicates(nums); // Calls your implementation assert k == expectedNums.length; for (int i = 0; i < k; i++) { assert nums[i] == expectedNums[i]; }
18
+
19
+
If all assertions pass, then your solution will be **accepted**.
20
+
21
+
**Example 1:**
22
+
23
+
**Input:** nums = [1,1,1,2,2,3]
24
+
25
+
**Output:** 5, nums = [1,1,2,2,3,\_]
26
+
27
+
**Explanation:** Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
28
+
29
+
**Example 2:**
30
+
31
+
**Input:** nums = [0,0,1,1,1,1,2,3,3]
32
+
33
+
**Output:** 7, nums = [0,0,1,1,2,3,3,\_,\_]
34
+
35
+
**Explanation:** Your function should return k = 7, with the first seven elements of nums being 0, 0, 1, 1, 2, 3 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
0 commit comments