Skip to content

Instantly share code, notes, and snippets.

@dluciano
Created November 8, 2022 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dluciano/f25c212bf15349f2290747c537804ade to your computer and use it in GitHub Desktop.
Save dluciano/f25c212bf15349f2290747c537804ade to your computer and use it in GitHub Desktop.
1544. Make The String Great
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