Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 20 public int solve(LinkedList<Integer> myBag, int remWeight) {
- 21 // implementation
- 22 int output;
- 23 int topWeight, nextRemWeight;
- 24 if (myBag.isEmpty() || remWeight == 0){
- 25 output = 1;
- 26 } else{
- 27 topWeight = myBag.pop();
- 28 if (topWeight > remWeight){
- 29 output = solve(myBag, remWeight);
- 30 } else {
- 31 nextRemWeight = remWeight - topWeight;
- 32 output = solve(myBag, remWeight) + solve(myBag, nextRemWeight);
- 33 }
- 34 }
- 35 return output;
- 36 }
Advertisement
Add Comment
Please, Sign In to add comment