07 2020 档案

摘要:1 class Solution { 2 public int findMagicIndex(int[] nums) { 3 int len = nums.length; 4 for (int i = 0; i < len; i++){ 5 if (i == nums[i]) 6 return i; 阅读全文
posted @ 2020-07-31 22:49 小小码农-安 阅读(158) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int integerBreak(int n) { 3 int[] dp = new int[n + 1]; //动态数组 4 for (int i = 2; i <= n; i++) { 5 for (int j = 1; j < i; j+ 阅读全文
posted @ 2020-07-30 22:48 小小码农-安 阅读(181) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int countOdds(int low, int high) { 3 if(low % 2 == 0 && high % 2 == 0) 4 return (high - low) / 2; 5 if(low % 2 != 0 && hig 阅读全文
posted @ 2020-07-29 23:13 小小码农-安 阅读(206) 评论(0) 推荐(0)
摘要:1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val 阅读全文
posted @ 2020-07-28 23:02 小小码农-安 阅读(139) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int splitArray(int[] nums, int m) { 3 int len = nums.length; 4 int[][] dp = new int[len + 1][m + 1]; //动态规划数组,dp[i][j]代表前i 阅读全文
posted @ 2020-07-28 22:41 小小码农-安 阅读(182) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public boolean isSubsequence(String s, String t) { 3 int len1 = s.length(), len2 = t.length(); 4 int indexs = 0, indext = 0; 5 wh 阅读全文
posted @ 2020-07-27 23:04 小小码农-安 阅读(180) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public boolean divisorGame(int N) { 3 boolean[] dp = new boolean[N + 3]; //初始化DP 4 dp[1] = false; //数字为1时失败 5 dp[2] = true; //数字为 阅读全文
posted @ 2020-07-24 23:15 小小码农-安 阅读(163) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int minPathSum(int[][] grid) { 3 int row = grid.length; 4 int col = grid[0].length; 5 int[][] dp = new int[row][col]; 6 if 阅读全文
posted @ 2020-07-23 22:25 小小码农-安 阅读(198) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int minArray(int[] numbers) { 3 int left = 0, right = numbers.length - 1; 4 while(left < right){ 5 int mid = (right - left 阅读全文
posted @ 2020-07-22 23:46 小小码农-安 阅读(231) 评论(0) 推荐(0)
摘要:1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode() {} 8 * Tre 阅读全文
posted @ 2020-07-21 23:04 小小码农-安 阅读(210) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int[] twoSum(int[] numbers, int target) { 3 int len = numbers.length; 4 int left = 0, right = len - 1; 5 int[] res = new i 阅读全文
posted @ 2020-07-20 22:21 小小码农-安 阅读(190) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int numWaterBottles(int numBottles, int numExchange) { 3 int res = numBottles; 4 while(numBottles / numExchange != 0) { 5 阅读全文
posted @ 2020-07-19 22:20 小小码农-安 阅读(198) 评论(0) 推荐(0)
摘要:解法一:暴力法 1 class Solution { 2 public boolean isInterleave(String s1, String s2, String s3) { 3 int index1 = 0, index2 = 0, index3 = 0; 4 if (check(s1, 阅读全文
posted @ 2020-07-18 22:52 小小码农-安 阅读(228) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int searchInsert(int[] nums, int target) { 3 int length = nums.length; 4 int left = 0, right = length - 1, ans = 0; 5 whil 阅读全文
posted @ 2020-07-17 22:14 小小码农-安 阅读(171) 评论(0) 推荐(0)
摘要:1 class Solution { 2 private int[] num; 3 public boolean isBipartite(int[][] graph) { 4 num = new int[graph.length]; 5 Arrays.fill(num, -1); 6 for (in 阅读全文
posted @ 2020-07-16 22:50 小小码农-安 阅读(190) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int numTrees(int n) { 3 int[] total = new int[n + 1]; 4 total[0] = 1; 5 total[1] = 1; 6 for (int i = 2; i <= n; ++i) { 7 f 阅读全文
posted @ 2020-07-15 22:31 小小码农-安 阅读(195) 评论(0) 推荐(0)
摘要:方法一: 1 class Solution { 2 public int minimumTotal(List<List<Integer>> triangle) { 3 int res = Integer.MAX_VALUE; 4 int height = triangle.size(); 5 if( 阅读全文
posted @ 2020-07-14 22:42 小小码农-安 阅读(253) 评论(0) 推荐(0)
摘要:1 public static int[] intersect(int[] nums1, int[] nums2) { 2 int len1 = nums1.length, len2 = nums2.length, index = 0; 3 int[] res = new int[len1 < le 阅读全文
posted @ 2020-07-13 22:06 小小码农-安 阅读(225) 评论(0) 推荐(0)
摘要:1 class Solution { 2 public int numIdenticalPairs(int[] nums) { 3 HashMap<Integer,Integer> index = new HashMap<Integer,Integer>(); 4 int total = 0; 5 阅读全文
posted @ 2020-07-12 22:00 小小码农-安 阅读(199) 评论(0) 推荐(0)