摘要: public int uniquePaths(int m,int n){ int[][] dp = new int[m][n]; for(int i=0;i<n;i++){ dp[0][i] = 1; } for(int i=0;i<m;i++){ dp[i][0] = 1; } for(int i 阅读全文
posted @ 2020-08-06 15:09 helloworldmybokeyuan 阅读(146) 评论(0) 推荐(0) 编辑
摘要: public int minPathSum(int[][] grid){ for(int i=0;i<grid.length;i++){ for(int j=0;j<grid[0].length;j++){ if(i==0 && j==0){ continue; }else if(i==0){ gr 阅读全文
posted @ 2020-08-06 15:07 helloworldmybokeyuan 阅读(259) 评论(0) 推荐(0) 编辑
摘要: public int climbStairs(int n){ if(n == 1){ return 1; } int[] dp = new int[n+1]; dp[1] = 1; dp[2] = 2; for(int i =3;i<=n;i++){ dp[i] = dp[i-1] + dp[i-2 阅读全文
posted @ 2020-08-06 15:06 helloworldmybokeyuan 阅读(77) 评论(0) 推荐(0) 编辑
摘要: public void move(int n, String from, String buffer, String to){ if(n==1){ System.out.println("from "+ from +" to " + to); } move(n-1, from, to, buffer 阅读全文
posted @ 2020-08-06 15:04 helloworldmybokeyuan 阅读(72) 评论(0) 推荐(0) 编辑
摘要: //144. Binary Tree Preorder Traversal (Medium) public List<Integer> preorderTraversal(TreeNode root){ List<Integer> ret = new ArrayList<Integer>(); if 阅读全文
posted @ 2020-08-06 15:02 helloworldmybokeyuan 阅读(128) 评论(0) 推荐(0) 编辑
摘要: public ListNode addTwoNumbers(ListNode l1,ListNode l2){ Stack<Integer> stack1 = buildStack(l1); Stack<Integer> stack2 = buildStack(l2); ListNode head 阅读全文
posted @ 2020-08-06 15:00 helloworldmybokeyuan 阅读(83) 评论(0) 推荐(0) 编辑
摘要: public ListNode reverseList(ListNode head){ ListNode newHead = new ListNode(); while(head!=null){ ListNode next = head.next; head.next = newHead.next; 阅读全文
posted @ 2020-08-06 14:58 helloworldmybokeyuan 阅读(68) 评论(0) 推荐(0) 编辑
摘要: //方法一 入度表(广度优先遍历) public boolean canFinish(int numCourses,int[][] prerequisites){ int[] indegrees = new int[numCourses]; List<List<Integer>> adjacency 阅读全文
posted @ 2020-08-06 14:56 helloworldmybokeyuan 阅读(160) 评论(0) 推荐(0) 编辑
摘要: public boolean isValid(String s){ Stack<Character> stack = new Stack<>(); Map<Character, Character> map = new HashMap<>(); map.put('{', '}'); map.put( 阅读全文
posted @ 2020-08-06 14:54 helloworldmybokeyuan 阅读(55) 评论(0) 推荐(0) 编辑
摘要: class MinStack{ private Stack<Integer> dataStack = new Stack<Integer>(); private Stack<Integer> minStack = new Stack<Integer>(); public void push(int 阅读全文
posted @ 2020-08-06 14:53 helloworldmybokeyuan 阅读(49) 评论(0) 推荐(0) 编辑
摘要: class MyStack{ private Queue<Integer> queue = new LinkedList<>(); public void push(int x){ queue.add(x); int cnt = queue.size(); while(cnt-->1){ queue 阅读全文
posted @ 2020-08-06 14:51 helloworldmybokeyuan 阅读(70) 评论(0) 推荐(0) 编辑
摘要: class MyQueue{ private Stack<Integer> in = new Stack<>(); private Stack<Integer> out = new Stack<>(); public void push(int x){ in.push(x); } public in 阅读全文
posted @ 2020-08-06 14:50 helloworldmybokeyuan 阅读(64) 评论(0) 推荐(0) 编辑
摘要: Input: [[1,1,0], [1,1,0], [0,0,1]] Output: 2 Explanation:The 0th and 1st students are direct friends, so they are in a friend circle. The 2nd student 阅读全文
posted @ 2020-08-06 14:45 helloworldmybokeyuan 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Input: 11000 11000 00100 00011 Output: 3 public int numIslands(char[][] grid){ if(grid==null || grid.length==0){ return 0; } int islandNum = 0; for(in 阅读全文
posted @ 2020-08-06 14:42 helloworldmybokeyuan 阅读(93) 评论(0) 推荐(0) 编辑
摘要: [[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,1,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,1,1,0,0,1,0,1,0,0], [0,1,0,0,1,1,0,0,1,1,1,0,0], [0,0 阅读全文
posted @ 2020-08-06 14:41 helloworldmybokeyuan 阅读(105) 评论(0) 推荐(0) 编辑
摘要: Input: beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] Output: 5 Explanation: As one shortest transformation is " 阅读全文
posted @ 2020-08-06 14:40 helloworldmybokeyuan 阅读(92) 评论(0) 推荐(0) 编辑
摘要: For example, Given board = [ ['A','B','C','E'], ['S','F','C','S'], ['A','D','E','E'] ] word = "ABCCED", -> returns true, word = "SEE", -> returns true 阅读全文
posted @ 2020-08-06 14:21 helloworldmybokeyuan 阅读(514) 评论(0) 推荐(0) 编辑
摘要: private static final String[] KEYS = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; public List<String> letterCombinations(String digits){ 阅读全文
posted @ 2020-08-06 14:18 helloworldmybokeyuan 阅读(106) 评论(0) 推荐(0) 编辑
摘要: private int result = 0; public int totalNQueens(int n){ int[] x = new int[n]; queens(x,n,0); return result; } private void queens(int[] x,int n,int ro 阅读全文
posted @ 2020-08-06 14:16 helloworldmybokeyuan 阅读(77) 评论(0) 推荐(0) 编辑
摘要: 1、不同数字全排列 [1,2,3] have the following permutations: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] public List<List<Integer>> permute(int[] n 阅读全文
posted @ 2020-08-06 14:11 helloworldmybokeyuan 阅读(130) 评论(0) 推荐(0) 编辑