回溯算法
。
Charlesjjc
这个作者很懒,什么都没留下…
展开
-
37. 解数独
37. 解数独class Solution { boolean[][] row = new boolean[9][9]; boolean[][] colomn = new boolean[9][9]; boolean[][][] block = new boolean[3][3][9]; char[][] res = new char[9][9]; public void solveSudoku(char[][] board) { for(in原创 2021-08-07 20:21:53 · 39 阅读 · 0 评论 -
51. N 皇后
51. N 皇后class Solution { List<List<String>> res = new ArrayList<>(); LinkedList<String> path = new LinkedList<>(); HashSet<Integer> column = new HashSet<>(); HashSet<Integer> diagonal1 = ne原创 2021-08-07 02:56:59 · 52 阅读 · 0 评论 -
332. 重新安排行程
332. 重新安排行程遇到挫折了,暴力回溯超时代码随想录Carl使用了TreeMap来升序保存每个起始点可以到达的机场以及次数,从字典序最小的开始加入路径做尝试,如果路径不通则return false,通了后续则不用遍历了,相当于做了剪枝操作。class Solution { private Deque<String> res; private Map<String, Map<String, Integer>> map; priva原创 2021-08-06 15:30:57 · 75 阅读 · 0 评论 -
47. 全排列 II
47. 全排列 IIclass Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> permuteUnique(int[] nums) { boolean[] used =原创 2021-08-06 03:32:14 · 107 阅读 · 0 评论 -
46. 全排列
46. 全排列class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> permute(int[] nums) { int[] used = new int[22];原创 2021-08-06 00:58:41 · 28 阅读 · 0 评论 -
491. 递增子序列
491. 递增子序列这题我没做出来class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> findSubsequences(int[] nums) { backt原创 2021-08-05 19:57:29 · 61 阅读 · 0 评论 -
90. 子集 II
90. 子集 IIclass Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> subsetsWithDup(int[] nums) { Arrays.sort(nums)原创 2021-08-05 04:27:17 · 50 阅读 · 0 评论 -
78. 子集
78. 子集easyclass Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> subsets(int[] nums) { backtracking(nums, 0)原创 2021-08-05 04:14:47 · 160 阅读 · 0 评论 -
93. 复原 IP 地址
93. 复原 IP 地址class Solution { List<String> res = new ArrayList<>(); StringBuffer path = new StringBuffer(); public List<String> restoreIpAddresses(String s) { backtracking(s, 0,0); return res; } publi原创 2021-08-05 03:18:36 · 66 阅读 · 0 评论 -
131. 分割回文串
131. 分割回文串class Solution { List<List<String>> res = new ArrayList<>(); LinkedList<String> path = new LinkedList<>(); public List<List<String>> partition(String s) { backtracking(0, s);原创 2021-08-05 02:51:46 · 95 阅读 · 0 评论 -
40. 组合总和 II
40. 组合总和 IIclass Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); public List<List<Integer>> combinationSum2(int[] candidates, int target) {原创 2021-08-05 02:20:45 · 40 阅读 · 0 评论 -
39. 组合总和
39. 组合总和class Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> path = new LinkedList<>(); HashSet<HashMap<Integer,Integer>> set = new HashSet(); HashMap<Integer,Inte原创 2021-08-04 23:36:57 · 39 阅读 · 0 评论 -
17. 电话号码的字母组合
17. 电话号码的字母组合class Solution { List<String> result = new ArrayList<>(); StringBuffer path = new StringBuffer(); int count = 0; public List<String> letterCombinations(String digits) { if(digits.length() == 0) retu原创 2021-08-04 21:18:58 · 47 阅读 · 0 评论 -
216. 组合总和 III
216. 组合总和 IIIclass Solution { List<List<Integer>> res = new ArrayList<>(); LinkedList<Integer> arr = new LinkedList<>(); public List<List<Integer>> combinationSum3(int k, int n) { findsum(k,n原创 2021-08-04 15:46:32 · 44 阅读 · 0 评论 -
77. 组合
77. 组合进入回溯了,学习学习学习class Solution { List<List<Integer>> res; LinkedList<Integer> arr = new LinkedList<>(); public List<List<Integer>> combine(int n, int k) { res = new ArrayList<>();原创 2021-08-04 15:19:43 · 41 阅读 · 0 评论