Skip to content

Instantly share code, notes, and snippets.

@thexande
Created October 25, 2019 18:28
Show Gist options
  • Save thexande/b3a656dc33be04fc386d162566f6d776 to your computer and use it in GitHub Desktop.
Save thexande/b3a656dc33be04fc386d162566f6d776 to your computer and use it in GitHub Desktop.
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