题目:
解析:
代码:
public int maxSubarraySumCircular(int[] nums) { int sum = 0; int n = nums.length; int[] f = new int[n+1]; int[] g = new int[n+1]; int ret = 0, fmax = -0x3f3f3f3f, gmin = Integer.MAX_VALUE; for(int i = 1; i <= n; i++){ int x = nums[i-1]; f[i] = Math.max(x,f[i-1] + x); fmax = Math.max(fmax,f[i]); g[i] = Math.min(x,g[i-1]+ x); gmin = Math.min(gmin,g[i]); sum += x; } return sum == gmin ? fmax : Math.max(fmax,sum-gmin); }