Skip to content

Commit

Permalink
Refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Dec 13, 2024
1 parent 4d7c990 commit ce8ba04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ public static class BacktrackingSolution
{
public static int CoinChange(int[] coins, int amount)
{
// Counter to store the total number of combinations
var count = 0;
Backtrack(0, amount);
return count;

void Backtrack(int start, int remaining)
{
// Base Case: if the remaining amount is 0, we have found a valid combination.
// The base case: if the remaining amount is 0, we have found a valid combination.
if (remaining == 0)
{
count++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static IEnumerable<object[]> CoinChangeTestCases()
yield return [new[] { 1, 2, 5 }, 5, 4];

yield return [new[] { 2 }, 3, 0];
yield return [new[] { 10 }, 10, 1];
yield return [new[] { 1, 3, 4 }, 6, 4];
yield return [new[] { 5 }, 5, 1];
yield return [new[] { 5 }, 2, 0];
Expand All @@ -61,5 +62,8 @@ public static IEnumerable<object[]> CoinChangeTestCases()
yield return [new[] { 1, 3, 4, 7 }, 15, 22];
yield return [new[] { 25, 50, 100 }, 30, 0];
yield return [new[] { 9, 6, 5, 1 }, 11, 6];

// LeetCode: Time Limit Exceeded
yield return [new[] { 3,5,7,8,9,10,11 }, 500, 35502874];
}
}

0 comments on commit ce8ba04

Please sign in to comment.