You are viewing a single comment's thread. Return to all comments →
PHP Recursion Solution Source: GeeksForGeeks!
function getWays($n, $coins, $i = 0): int { static $ways = []; if (isset($ways[$n][$i])) return $ways[$n][$i]; if ($n == 0) return 1; if ($n < 0) return 0; if ($i == count($coins)) return 0; $count = getWays($n - $coins[$i], $coins, $i); $count += getWays($n, $coins, $i + 1); return $ways[$n][$i] = $count; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Coin Change Problem
You are viewing a single comment's thread. Return to all comments →
PHP Recursion Solution Source: GeeksForGeeks!