Created
November 8, 2022 10:11
-
-
Save dluciano/f25c212bf15349f2290747c537804ade to your computer and use it in GitHub Desktop.
1544. Make The String Great
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public string MakeGood(string s) { | |
if(s.Length <= 1) | |
return s; | |
var sb = new StringBuilder(s); | |
var i = 1; | |
while(i < sb.Length){ | |
if(Math.Abs(sb[i] - sb[i - 1]) == ('a' - 'A')){ | |
sb.Remove(i, 1); | |
sb.Remove(i - 1, 1); | |
i = i - 2 < 0 ? 0 : i - 2; | |
} | |
i++; | |
} | |
return sb.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment