Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 898c42a

Browse files
新增java用set2k
1 parent a039519 commit 898c42a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎problems/0491.递增子序列.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ public:
203203

204204

205205
### Java
206+
```Java
207+
//using set, aligned with the unimproved method
208+
class Solution {
209+
List<List<Integer>> result = new ArrayList<>();
210+
List<Integer> path = new ArrayList<>();
211+
public List<List<Integer>> findSubsequences(int[] nums) {
212+
backTracking(nums, 0);
213+
return result;
214+
}
215+
private void backTracking(int[] nums, int startIndex){
216+
if(path.size() >= 2)
217+
result.add(new ArrayList<>(path));
218+
HashSet<Integer> hs = new HashSet<>();
219+
for(int i = startIndex; i < nums.length; i++){
220+
if(!path.isEmpty() && path.get(path.size() -1 ) > nums[i] || hs.contains(nums[i]))
221+
continue;
222+
hs.add(nums[i]);
223+
path.add(nums[i]);
224+
backTracking(nums, i + 1);
225+
path.remove(path.size() - 1);
226+
}
227+
}
228+
}
229+
```
206230

207231
```java
208232
class Solution {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /