LeetCode: Make The String Great Solution
Keep removing until all is goodImplementation
1var makeGood = function (s) {2 s = s.split("")34 const notGood = (a, b) => a !== b && a.toLowerCase() === b.toLowerCase()56 let allGood = false78 while (!allGood) {9 allGood = true1011 for (let i = 0; i < s.length - 1; i++) {12 if (notGood(s[i], s[i + 1])) {13 allGood = false14 s.splice(i, 2)15 }16 }17 }1819 return s.join("")20}
References
Comments
Loading comments...
Tags
leetcode
string
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.