Title: #254 - Factor Combinations - LeetCode JavaScript Solutions
Open Graph Title: #254 - Factor Combinations - LeetCode JavaScript Solutions
X Title: #254 - Factor Combinations - LeetCode JavaScript Solutions
Description: Numbers can be regarded as the product of their factors. For example, 8 = 2 x 2 x 2 = 2 x 4. Given an integer n, return all possible combina...
Open Graph Description: Numbers can be regarded as the product of their factors. For example, 8 = 2 x 2 x 2 = 2 x 4. Given an integer n, return all possible combina...
X Description: Numbers can be regarded as the product of their factors. For example, 8 = 2 x 2 x 2 = 2 x 4. Given an integer n, return all possible combina...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/factor-combinations
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/factor-combinations","name":"#254 - Factor Combinations - LeetCode JavaScript Solutions","description":"Numbers can be regarded as the product of their factors. For example, 8 = 2 x 2 x 2 = 2 x 4. Given an integer n, return all possible combina...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} n\n * @return {number[][]}\n */\nvar getFactors = function(n) {\n const result = [];\n findFactors(n, 2, []);\n return result;\n\n function findFactors(currentNum, start, combination) {\n for (let i = start; i * i <= currentNum; i++) {\n if (currentNum % i === 0) {\n const nextNum = currentNum / i;\n if (nextNum >= i && nextNum < currentNum) {\n result.push([...combination, i, nextNum]);\n findFactors(nextNum, i, [...combination, i]);\n }\n }\n }\n }\n};","keywords":"LeetCode 254, #254 - Factor Combinations, Medium, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/factor-combinations |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/factor-combinations/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0254-factor-combinations.js |
| Backtracking | https://leetcodejavascript.com/tags/backtracking |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow