Skip to content

Commit 8cadae6

Browse files
author
github-actions
committed
Format: Google java formatter
1 parent 1e4d747 commit 8cadae6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

DynamicProgramming/TargetSum/Solution.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
/**
66
* * Target Sum (Variation of 0/1 Knapsack)
7-
*
7+
*
88
* LeetCode Problem: https://leetcode.com/problems/target-sum/
99
*/
10-
1110
public class Solution {
1211
public int findTargetSumWays(int[] array, int target) {
1312
int sum = Arrays.stream(array).sum();
@@ -17,7 +16,7 @@ public int findTargetSumWays(int[] array, int target) {
1716

1817
/**
1918
* * Dynamic Programming Approach
20-
*
19+
*
2120
* * TC: O(ns)
2221
* * SC: O(ns)
2322
*/
@@ -27,12 +26,12 @@ private int countOfSubsetsDP(int[] array, int sum, int target) {
2726
/**
2827
* Equation I: S1 - S2 = difference
2928
* Equation II: S1 + S2 = sum(array)
30-
*
29+
*
3130
* Adding I and II,
32-
*
31+
*
3332
* 2S1 = sum(array) + difference
3433
* so, S1 = (sum(array) + difference) / 2
35-
*
34+
*
3635
* Now, we need to find the count of
3736
* subsets equal to a given sum, which
3837
* is S1
@@ -77,4 +76,4 @@ public static void main(String[] args) {
7776
// should be 5
7877
System.out.println(solution.findTargetSumWays(new int[] {1, 1, 1, 1, 1}, 3));
7978
}
80-
}
79+
}

0 commit comments

Comments
 (0)