上一页 1 ··· 5 6 7 8 9
摘要: 很经典的DP题,用dp[i]纪录[0,i]的数组的最大子序和,往后递推实际上就是判断 nums[i+1]是否能给dp[i+1]带来增益效果,使得dp[i+1]>dp[i] public int maxSubArray(int[] nums) { // dp[i]纪录以截至i结尾的最大子序和 int[ 阅读全文
posted @ 2021-03-26 10:40 jchen104 阅读(42) 评论(0) 推荐(0) 编辑
摘要: 第一眼想到的思路是迭代,必然存在 res*res<x<(res+1)*(res+1),这样的话在n^0.5的时间内可以处理好, 于是有以下代码 public int mySqrt(int x) { int res = 0; // 必然存在 res*res<x<(res+1)*(res+1) whil 阅读全文
posted @ 2021-03-26 10:12 jchen104 阅读(68) 评论(0) 推荐(0) 编辑
摘要: 题目1. 两数之和 方法1,暴力求解,2层循环,时间复杂度O(n^2),空间复杂度O(1) public int[] twoSum(int[] nums, int target) { int[] res = new int[2]; for(int i=0;i<nums.length;i++){ fo 阅读全文
posted @ 2020-09-27 00:01 jchen104 阅读(77) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9