dp, 以这个数字为结尾的最大子数组和

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
/**
* dp, 以这个数字为结尾的最大子数组和
*/
public int maxSubArray(int[] nums) {
int f = nums[0];
int ans = f;
for (int i = 1; i < nums.length; i++) {
f = Math.max(f + nums[i], nums[i]);
ans = Math.max(ans, f);
}
return ans;
}
}

Comments
Recent Posts
Untitled
Categories
Tags
Website Info
Article Count :
2
Total Word Count :
1.6k
Unique Visitors :
Page Views :
Last Update :