Skip to content

Commit e33d653

Browse files
author
wb-hjk570755
committed
动态规划
1 parent 0d73c0e commit e33d653

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/com/blankj/easy/_053/Solution.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ public static void main(String[] args) {
4545
int[] nums0 = new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4};
4646
System.out.println(solution.maxSubArray(nums0));
4747
}
48+
49+
public int maxSubArrayByD(int[] nums) {
50+
int len = nums.length, dp = nums[0], max = dp;
51+
for (int i = 1; i < len; ++i) {
52+
dp = nums[i] + (dp > 0 ? dp : 0);
53+
if (dp > max) {
54+
max = dp;
55+
}
56+
}
57+
return max;
58+
}
4859
}

0 commit comments

Comments
 (0)