From ce8ba04c83b20872787f3cbe9723294855e8433b Mon Sep 17 00:00:00 2001 From: eminencegrs Date: Fri, 13 Dec 2024 23:54:37 +0100 Subject: [PATCH] Refactoring. --- .../LeetCode.Challenges/CoinChangeII/BacktrackingSolution.cs | 3 +-- .../CoinChangeII/BacktrackingSolutionTests.cs | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/LeetCode/src/LeetCode.Challenges/CoinChangeII/BacktrackingSolution.cs b/LeetCode/src/LeetCode.Challenges/CoinChangeII/BacktrackingSolution.cs index 5e9aa0a..06ee5eb 100644 --- a/LeetCode/src/LeetCode.Challenges/CoinChangeII/BacktrackingSolution.cs +++ b/LeetCode/src/LeetCode.Challenges/CoinChangeII/BacktrackingSolution.cs @@ -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++; diff --git a/LeetCode/tests/LeetCode.Challenges.UnitTests/CoinChangeII/BacktrackingSolutionTests.cs b/LeetCode/tests/LeetCode.Challenges.UnitTests/CoinChangeII/BacktrackingSolutionTests.cs index d92b371..4c01bac 100644 --- a/LeetCode/tests/LeetCode.Challenges.UnitTests/CoinChangeII/BacktrackingSolutionTests.cs +++ b/LeetCode/tests/LeetCode.Challenges.UnitTests/CoinChangeII/BacktrackingSolutionTests.cs @@ -48,6 +48,7 @@ public static IEnumerable 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]; @@ -61,5 +62,8 @@ public static IEnumerable 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]; } }