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;
阅读全文
摘要: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+
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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; //数字为
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:1 class Solution { 2 public int numWaterBottles(int numBottles, int numExchange) { 3 int res = numBottles; 4 while(numBottles / numExchange != 0) { 5
阅读全文
摘要:解法一:暴力法 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,
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要:方法一: 1 class Solution { 2 public int minimumTotal(List<List<Integer>> triangle) { 3 int res = Integer.MAX_VALUE; 4 int height = triangle.size(); 5 if(
阅读全文
摘要: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
阅读全文
摘要:1 class Solution { 2 public int numIdenticalPairs(int[] nums) { 3 HashMap<Integer,Integer> index = new HashMap<Integer,Integer>(); 4 int total = 0; 5
阅读全文

浙公网安备 33010602011771号