GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/src/MaximumSubarray.java at master · LeBW/leetcode Expand file tree/ Copy pathMaximumSubarray.javaMore file actions 18 lines (18 loc) · 571 Bytes / Copy pathMaximumSubarray.javaFile metadata and controls18 lines (18 loc) · 571 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 /** * 53. Maximum Subarray * Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. * 动态规划 * @author LBW */ public class MaximumSubarray { public int maxSubarray(int[] nums) { int[] dp = new int[nums.length + 1]; dp[0] = 0; int max = Integer.MIN_VALUE; for (int i = 1; i <= nums.length; i++) { dp[i] = Math.max(dp[i - 1] + nums[i - 1], nums[i - 1]); max = Math.max(max, dp[i]); } return max; } } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |