摘要:
public boolean exist(char[][] board, String word) { int m = board.length; int n = board[0].length; boolean[][] visited = new boolean[m][n]; int len = 阅读全文
摘要:
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 阅读全文
摘要:
动态规划 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 - 阅读全文
摘要:
用哈希表 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( 阅读全文
摘要:
import java.util.Stack; public class CQueue { Stack<Integer> stack1 = new Stack<>(); Stack<Integer> stack2 = new Stack<>(); public CQueue() { } public 阅读全文
摘要:
递归: public TreeNode buildTree(int[] preorder, int[] inorder) { int len = preorder.length; if(len == 0) return null; TreeNode head = new TreeNode(preor 阅读全文