摘要:
很经典的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[ 阅读全文
摘要:
第一眼想到的思路是迭代,必然存在 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 阅读全文