摘要: public boolean exist(char[][] board, String word) { int m = board.length; int n = board[0].length; boolean[][] visited = new boolean[m][n]; int len = 阅读全文
posted @ 2020-08-07 16:55 欣姐姐 阅读(92) 评论(0) 推荐(0) 编辑
摘要: class Solution { public int minArray(int[] numbers) { int n = numbers.length; if(n == 1) return numbers[0]; if(n == 2) return Math.min(numbers[0],numb 阅读全文
posted @ 2020-08-07 15:29 欣姐姐 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 动态规划 public int numWays(int n) { if(n == 0 || n == 1) return 1; int[] dp = new int[n+1]; dp[0] = 1; dp[1] = 1; for(int i = 2;i<=n;i++){ int m = dp[i - 阅读全文
posted @ 2020-08-07 11:32 欣姐姐 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 用哈希表 public int fib(int n) { Map<Integer,Integer> map = new HashMap<>(); map.put(0,0); map.put(1,1); if(map.containsKey(n)){ return map.get(n); } for( 阅读全文
posted @ 2020-08-07 11:22 欣姐姐 阅读(76) 评论(0) 推荐(0) 编辑
摘要: import java.util.Stack; public class CQueue { Stack<Integer> stack1 = new Stack<>(); Stack<Integer> stack2 = new Stack<>(); public CQueue() { } public 阅读全文
posted @ 2020-08-07 11:02 欣姐姐 阅读(89) 评论(0) 推荐(0) 编辑
摘要: 递归: public TreeNode buildTree(int[] preorder, int[] inorder) { int len = preorder.length; if(len == 0) return null; TreeNode head = new TreeNode(preor 阅读全文
posted @ 2020-08-07 10:09 欣姐姐 阅读(82) 评论(0) 推荐(0) 编辑