Created
October 25, 2019 18:28
-
-
Save thexande/b3a656dc33be04fc386d162566f6d776 to your computer and use it in GitHub Desktop.
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
import Foundation | |
var stack = [Character]() | |
func isPalendrome(subject: String) -> Bool { | |
var reversed = "" | |
var sanitized = "" | |
for character in subject where character.isLetter { | |
sanitized.append(character) | |
stack.append(character) | |
} | |
while stack.isEmpty == false { | |
reversed.append(stack.removeLast()) | |
} | |
return reversed == sanitized | |
} | |
print(isPalendrome(subject: "a man a plan a canal panama")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment