Skip to content

Instantly share code, notes, and snippets.

@GregoryMaks
Created February 20, 2026 11:32
Show Gist options
  • Select an option

  • Save GregoryMaks/10e7f1cce142e1953e3466bf3ac29260 to your computer and use it in GitHub Desktop.

Select an option

Save GregoryMaks/10e7f1cce142e1953e3466bf3ac29260 to your computer and use it in GitHub Desktop.
class Solution {
func removePalindromeSub(_ s: String) -> Int {
guard s.count > 0 else { return 0 }
if isPalindrome(s) { return 1 }
return 2
}
private func isPalindrome(_ s: String) -> Bool {
let b = "b".utf8CString[0]
let utf = s.utf8CString.dropLast()
var l = 0
var r = utf.count - 1
while utf[l] == utf[r], l<=r {
l += 1
r -= 1
}
return utf[l] == utf[r]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment