Skip to content

Commit 36e9a1d

Browse files
authored
Update TheCoinChangeProblem.cpp
1 parent 52bd42e commit 36e9a1d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Famous-Coding-Interview-Problems/TheCoinChangeProblem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int vis[N][N], dp[N][N];
1111
int ways(int pos, int S) {
1212
if(pos == n) return S == 0;
1313
int &ans = dp[pos][S];
14-
if(vis[pos][S]) return ans; vis[pos][S] = 1, ans = 0;
14+
if(vis[pos][S]) return ans; vis[pos][S] = 1, ans = 0;
1515
int times = 0;
1616
while(times*A[pos] <= S) ans += ways(pos+1, S-times*A[pos]), times++;
1717
return ans;
@@ -20,9 +20,9 @@ int ways(int pos, int S) {
2020
//Faster than ways function as it causes only two transitions
2121
int fasterWays(int pos, int S) {
2222
if(pos == n) return S == 0;
23-
if(S < 0) return 0;
23+
if(S < 0) return 0;
2424
int &ans = dp[pos][S];
25-
if(vis[pos][S]) return ans; vis[pos][S] = 1, ans = 0;
25+
if(vis[pos][S]) return ans; vis[pos][S] = 1, ans = 0;
2626
ans = ways(pos, S-A[pos]) + ways(pos+1, S);
2727
return ans;
2828
}

0 commit comments

Comments
 (0)