Leetcode / 1544. Make The String Great
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public String makeGood(String s) {
StringBuilder sb = new StringBuilder(s);
for (int i = 0; i < sb.length() - 1; )
{
int diff = sb.codePointAt(i) - sb.codePointAt(i + 1);
if (diff == 32 || diff == -32)
{
sb.delete(i, i + 2);
if (i > 0)
{
i--;
}
}
else
{
i++;
}
}
return sb.toString();
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: