上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 36 下一页
摘要: 动态规划 class Solution { public int fib(int n) { /** * 因为n从0开始,初始了dp[0]和dp[1] * 为了避免dp[1]空指针异常,提前判断一下 */ if (n < 1){ return n; } int[] dp = new int[n + 1 阅读全文
posted @ 2022-01-18 13:59 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
摘要: 贪心 import java.util.Arrays; class Solution { public int findContentChildren(int[] g, int[] s) { /** * 贪心算法 * 将胃口大小和饼干大小排序,按照最大的饼干给最大的胃口的原则,依次分配饼干 * 如果 阅读全文
posted @ 2022-01-17 21:07 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要: 回溯 class Solution { public void solveSudoku(char[][] board) { backtracking(board); } public boolean backtracking(char[][] board) { /** * 递归遍历每个空位放9个数字 阅读全文
posted @ 2022-01-17 17:43 振袖秋枫问红叶 阅读(34) 评论(0) 推荐(0)
摘要: 回溯 import java.util.Arrays; class Solution { int sum = 0; public int totalNQueens(int n) { /** * 使用二维数组存储棋盘,最后再转换为列表 * 默认填充'.' */ char[][] chars = new 阅读全文
posted @ 2022-01-17 15:27 振袖秋枫问红叶 阅读(27) 评论(0) 推荐(0)
摘要: 深度优先搜索 import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; class Solution { int m; int n; int[][] 阅读全文
posted @ 2022-01-17 14:21 振袖秋枫问红叶 阅读(47) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int m; int n; boolean[][] used; int[][] move = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; public void solve(char[][] board) { m = boa 阅读全文
posted @ 2022-01-16 22:44 振袖秋枫问红叶 阅读(34) 评论(0) 推荐(0)
摘要: 深度优先搜索 import java.util.ArrayList; import java.util.HashMap; class Solution { int m; int n; boolean[][] used; int[][] move = {{0, 1}, {1, 0}, {0, -1}, 阅读全文
posted @ 2022-01-16 21:53 振袖秋枫问红叶 阅读(109) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int m; int n; boolean[][] used; int sum = 0; int[][] move = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; public int islandPerimeter(int 阅读全文
posted @ 2022-01-16 18:56 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int m; int n; boolean[][] used; int[][] move = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; public int maxAreaOfIsland(int[][] grid) { 阅读全文
posted @ 2022-01-16 17:50 振袖秋枫问红叶 阅读(28) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { int m; int n; int sum; boolean[][] used; int[][] move = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; public int numIslands(char[][] gri 阅读全文
posted @ 2022-01-16 16:59 振袖秋枫问红叶 阅读(36) 评论(0) 推荐(0)
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 36 下一页