Predict the Winner



For approach #4, code is also wrong. use this code with example '1,5,4' it return false, but right ans should be true;
the correct code below:
public boolean PredictTheWinner(int[] nums) {
int[] dp = Arrays.copyOf(nums,nums.length);
for (int s = nums.length; s >= 0; s) {
for (int e = s + 1; e < nums.length; e++) {
int a = nums[s]  dp[e];
int b = nums[e]  dp[e  1];
dp[e] = Math.max(a, b);
}
}
return dp[nums.length  1] >= 0;
}

@wddtsps
Agree!
Would you plz explain more why copy the original array?public boolean PredictTheWinner(int[] nums) { int[] dp = Arrays.copyOf(nums, nums.length); for (int s = nums.length; s >= 0; s) { for (int e = s + 1; e < nums.length; e++) { int a = nums[s]  dp[e]; int b = nums[e]  dp[e  1]; dp[e] = Math.max(a, b); } } return dp[nums.length  1] >= 0; }