LeetCode: Make The String Great Solution

Keep removing until all is good

Implementation

1var makeGood = function (s) {
2 s = s.split("")
3
4 const notGood = (a, b) => a !== b && a.toLowerCase() === b.toLowerCase()
5
6 let allGood = false
7
8 while (!allGood) {
9 allGood = true
10
11 for (let i = 0; i < s.length - 1; i++) {
12 if (notGood(s[i], s[i + 1])) {
13 allGood = false
14 s.splice(i, 2)
15 }
16 }
17 }
18
19 return s.join("")
20}

References

Original problem

Comments

Loading comments...

Tags

leetcode

string

Next Post

LeetCode: Min Stack

Nov 15, 2022

Linked list in action

Previous Post

LeetCode: Number of Ways to Split a String

Nov 8, 2022

Playing with indexes

HoningJS

Search Posts