随笔分类 - DFS
摘要:class Solution { public int numIslands(char[][] grid) { int count=0; for(int i=0;i=grid.length||j=grid[0].length||grid[i][j]!='1') return; grid[i][j]='2'; ...
阅读全文
摘要:class Solution { public List wordBreak(String s, List wordDict) { Map> map=new HashMap>(); wordBreak(s, map, wordDict); return map.get(s); } private void wordBreak...
阅读全文
摘要:class Solution { public List> partition(String s) { List> res=new ArrayList>(); generatePartition(0,new ArrayList(),res,s); return res; } private void generatePart...
阅读全文
摘要:public class Solution { public void solve(char[][] board) { if (board.length == 0 || board[0].length == 0) return; int m = board.length; int n = board[0].length; bool...
阅读全文
摘要:class Solution { int maxPathSum; public int maxPathSum(TreeNode root) { maxPathSum=Integer.MIN_VALUE; seachPathSum(root); return maxPathSum; } private int seac...
阅读全文
摘要:class Solution { public List> pathSum(TreeNode root, int sum) { List> res=new ArrayList>(); pathSum(root, sum, new ArrayList(), res); return res; } private void pa...
阅读全文
摘要:class Solution { ListNode lnode=null; public TreeNode sortedListToBST(ListNode head) { int size=0; ListNode p=head; while(p!=null) { p=p.next; ...
阅读全文
摘要:public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return buildTree(inorder, 0, inorder.length-1, postorder, 0, postorder.length-1); } private TreeNo...
阅读全文
摘要:public class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { return buildTree(preorder, 0, preorder.length-1, inorder, 0, inorder.length); } private TreeNode bu...
阅读全文
摘要:class Solution { public List generateTrees(int n) { if(n==0) return new ArrayList(); return generateTrees(1, n); } private List generateTrees(int i, int j) { ...
阅读全文
摘要:class Solution { public List restoreIpAddresses(String s) { List res=new ArrayList(); restoreIpAddresses("", 0, 0, s, res); return res; } private void restoreIpAdd...
阅读全文
摘要:public class Solution { public List> subsetsWithDup(int[] nums) { List> res=new ArrayList>(); Arrays.sort(nums); subsetsWithDup(0, new ArrayList(), res, nums); ret...
阅读全文
摘要:class Solution { public boolean isScramble(String s1, String s2) { if(s1.length()==0||s1.equals(s2)) return true; int[] cnt=new int[128]; for(int i=0;i<s1.leng...
阅读全文
摘要:class Solution { public boolean exist(char[][] board, String word) { if(board.length==0||board[0].length==0) return false; boolean[][] used=new boolean[board.length][b...
阅读全文
摘要:class Solution { public List> subsets(int[] nums) { List> res=new ArrayList>(); subsets(0, new ArrayList(), res, nums); return res; } private void subsets(int idx,...
阅读全文
摘要:class Solution { public List> combine(int n, int k) { List> res=new ArrayList>(); combine(n, k, new ArrayList(), res); return res; } private void combine(int num, ...
阅读全文
摘要:class Solution { public int totalNQueens(int n) { int[][] board=new int[n][n]; return totalNQueens(0, board); } private int totalNQueens(int i, int[][] board) { ...
阅读全文
摘要:class Solution { public List> solveNQueens(int n) { int[][] board=new int[n][n]; List> res=new ArrayList>(); nQueens(0,board,res); return res; } private vo...
阅读全文
摘要:public class Solution { public List> permuteUnique(int[] nums) { List> ret=new ArrayList>(); Arrays.sort(nums); boolean[] used=new boolean[nums.length]; permute(ne...
阅读全文
摘要:class Solution { public List> combinationSum2(int[] candidates, int target) { List> ret=new ArrayList>(); Arrays.sort(candidates); boolean[] used=new boolean[candidates.le...
阅读全文

浙公网安备 33010602011771号