Memoization approach working but Tabultion fails in a particular problem.Why?

Published: 25/03/2020
Memoization approach working but Tabultion fails in a particular problem.Why?
Source: STACKOVERFLOW.COM

problem link: https://leetcode.com/problems/target-sum/ I tried doing this by top down and bottom up approaches.The top down worked but bottom up didn't.Please tell me why. The top down approach-> class Solution { public: int findTargetSumWays(vector<int>& nums, int S) { int sum=accumulate(nums.begin(),nums.end(),0); if((sum+S)%2!=0) return false; int target=(sum+S)/2; if(target>sum)

Read more
Related news
Comment
FACEBOOK