Update Leetcode 题解 - 动态规划.md

fixed 494\. Target Sum (Medium)
This commit is contained in:
Gabriel 2023-01-11 16:01:23 +08:00 committed by GitHub
parent 2c31eddf34
commit b672479242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -807,7 +807,7 @@ sum(P) + sum(N) + sum(P) - sum(N) = target + sum(P) + sum(N)
```java ```java
public int findTargetSumWays(int[] nums, int S) { public int findTargetSumWays(int[] nums, int S) {
int sum = computeArraySum(nums); int sum = computeArraySum(nums);
if (sum < S || (sum + S) % 2 == 1) { if (sum < Math.abs(S) || (sum + S) % 2 == 1) {
return 0; return 0;
} }
int W = (sum + S) / 2; int W = (sum + S) / 2;