Created
February 20, 2026 11:32
-
-
Save GregoryMaks/10e7f1cce142e1953e3466bf3ac29260 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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