Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: - 125 Valid Palindrome
- func isPalindrome(_ s: String) -> Bool {
- let s: [Character] = Array(s)
- var l = 0
- var r = s.count-1
- while l < r {
- // Пока не буква И не цифра двигаем указатель
- while (!s[l].isLetter && !s[l].isNumber) && l < r {
- l += 1
- }
- while (!s[r].isLetter && !s[r].isNumber) && l < r {
- r -= 1
- }
- if s[l].lowercased() != s[r].lowercased() {
- return false
- }
- l += 1
- r -= 1
- }
- return true
- }
- isPalindrome("A man, a plan, a canal: Panama")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement