vault backup: 2022-09-21 14:35:34

This commit is contained in:
juan 2022-09-21 14:35:34 +08:00
parent 8aa7a6d3bb
commit 2a1004a7c7
2 changed files with 38 additions and 3 deletions

View file

@ -16,7 +16,7 @@
> >
> ##### Revisions: > ##### Revisions:
> >
> N/A > 2022-09-21
##### Related topics: ##### Related topics:
@ -110,3 +110,34 @@ public:
} }
}; };
``` ```
Alternative solution using private values
```cpp
class Solution {
vector<vector<int>> ans;
vector<int> combs = {};
int N, K;
void backtrack(int cur) {
if (combs.size() == K) {
// we reached the end, should push to the answer array
ans.push_back(combs);
return;
} else if (cur <= N) {
combs.push_back(cur);
backtrack(cur + 1);
combs.pop_back();
backtrack(cur + 1);
}
}
public:
vector<vector<int>> combine(int n, int k) {
N = n;
K = k;
backtrack(1);
return ans;
}
};
```

View file

@ -16,13 +16,13 @@
> >
> ##### Revisions: > ##### Revisions:
> >
> N/A > 2022-09-21
##### Related topics: ##### Related topics:
##### Links: ##### Links:
- [Link to problem](https://leetcode.com/problems/implement-queue-using-stacks/submissions/) - [Link to problem](https://leetcode.com/problems/implement-queue-using-stacks/)
--- ---
@ -52,15 +52,19 @@ Implement the `MyQueue` class:
``` ```
**Output** **Output**
```
[null, null, null, 1, 1, false] [null, null, null, 1, 1, false]
```
**Explanation** **Explanation**
```
MyQueue myQueue = new MyQueue(); MyQueue myQueue = new MyQueue();
myQueue.push(1); // queue is: [1] myQueue.push(1); // queue is: [1]
myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue) myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
myQueue.peek(); // return 1 myQueue.peek(); // return 1
myQueue.pop(); // return 1, queue is [2] myQueue.pop(); // return 1, queue is [2]
myQueue.empty(); // return false myQueue.empty(); // return false
```
#### Constraints #### Constraints