标签:array http turn find ima 相等 new alt 子序列
class Solution { List<Integer> temp = new ArrayList<Integer>(); List<List<Integer>> ans = new ArrayList<List<Integer>>(); public List<List<Integer>> findSubsequences(int[] nums) { dfs(0, -101, nums); return ans; } public void dfs(int cur, int last, int[] nums) { if (cur == nums.length) { if (temp.size() >= 2) ans.add(new ArrayList<Integer>(temp)); return; } if (nums[cur] >= last) { temp.add(nums[cur]); dfs(cur + 1, nums[cur], nums); temp.remove(temp.size() - 1); } if (nums[cur] != last) dfs(cur + 1, last, nums); // 和上一个值不相等才递归到下一层 } }
标签:array http turn find ima 相等 new alt 子序列
原文地址:https://www.cnblogs.com/yonezu/p/13561587.html