LeetCode: Letter Case Permutation Solution
1const recursion = function (chars, set, i = 0) {2 set.add(chars.join(""))34 if (i === chars.length) {5 return6 }78 for (let j = i; j < chars.length; j++) {9 let temp = chars[j]10 chars[j] =11 temp === temp.toLowerCase() ? temp.toUpperCase() : temp.toLowerCase()12 recursion(chars, set, j + 1)13 chars[j] = temp14 }15}1617/**18 * @param {string} S19 * @return {string[]}20 */21var letterCasePermutation = function (S) {22 const chars = S.split("")23 let set = new Set()24 recursion(chars, set)25 return Array.from(set)26}
Comments
Loading comments...
Tags
leetcode
backtracking
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Previous Post
LeetCode: Is Graph Bipartite
Feb 15, 2021