Title: #77 - Combinations - LeetCode JavaScript Solutions
Open Graph Title: #77 - Combinations - LeetCode JavaScript Solutions
X Title: #77 - Combinations - LeetCode JavaScript Solutions
Description: Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. ...
Open Graph Description: Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. ...
X Description: Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/combinations
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/combinations","name":"#77 - Combinations - LeetCode JavaScript Solutions","description":"Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {number} n\n * @param {number} k\n * @return {number[][]}\n */\nvar combine = function(n, k) {\n const result = [];\n backtrack(result, n, k);\n return result;\n};\n\nfunction backtrack(result, n, k, combination = [], offset = 1) {\n if (combination.length === k) {\n result.push(combination);\n } else {\n while (offset <= n) {\n backtrack(result, n, k, [...combination, offset], ++offset);\n }\n }\n}","keywords":"LeetCode 77, #77 - 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/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/combinations/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0077-combinations.js |
| Backtracking | https://leetcodejavascript.com/tags/backtracking |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow