Skip to content

Commit ad027ba

Browse files
committed
459 491
1 parent 26a7781 commit ad027ba

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Leetcode刷题记录
4343
+ No.77 [python](python/77.py)
4444
+ No.97 [python](python/97.py)
4545
+ No.111 [cpp](cpp/111.cpp) easy
46+
+ No.491 [cpp](cpp/491.cpp)
4647
+ No.529 [cpp](cpp/529.cpp)
4748
+ No.733 [cpp](cpp/733.cpp)
4849

@@ -67,6 +68,7 @@ Leetcode刷题记录
6768

6869
+ No.136 [cpp](cpp/136.cpp)
6970
+ No.64 [cpp](cpp/64.cpp) [python](python/64.py)
71+
+ No.459 [cpp](cpp/459.cpp)
7072

7173
### 双指针
7274

cpp/459.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution {
5+
6+
bool repeatedSubstringPattern(string s) {
7+
return (s+s).find(s, 1) != s.size();
8+
}
9+
};

cpp/491.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
class Solution {
5+
public:
6+
/**
7+
* dfs + set去重复
8+
*
9+
*/
10+
vector<vector<int>> findSubsequences(vector<int>& nums) {
11+
// unordered_map<int, vector<int>> cache; /*第一个是int(pos), 第二个是vector<int>, 存的缓存的结果*/
12+
vector<int> pre;
13+
set<vector<int>> res;
14+
dfs(nums, 0, pre, -101, res);
15+
return vector<vector<int>>(res.begin(), res.end());
16+
}
17+
18+
void dfs(vector<int>& nums, int pos, vector<int> pre, int pre_value, set<vector<int>> &res) {
19+
int n = nums.size();
20+
21+
if (pre.size()>1)
22+
res.insert(pre);
23+
for (int i = pos; i < n; ++i) {
24+
if (nums[i] >= pre_value) {
25+
pre.push_back(nums[i]);
26+
dfs(nums, i+1, pre, nums[i], res);
27+
pre.pop_back(); // 吐出去
28+
}
29+
}
30+
}
31+
};

0 commit comments

Comments
 (0)