Skip to content

Instantly share code, notes, and snippets.

@lawreyios
Created February 11, 2019 01:44
Show Gist options
  • Select an option

  • Save lawreyios/36776a6e818b520e26e5655cc7cc323d to your computer and use it in GitHub Desktop.

Select an option

Save lawreyios/36776a6e818b520e26e5655cc7cc323d to your computer and use it in GitHub Desktop.
Palindrome using String Index (Swift)
func isPalindrome(inputString: String) -> Bool {
let stringLength = inputString.count
var position = 0
while position < stringLength / 2 {
let startIndex = inputString.index(inputString.startIndex, offsetBy: position)
let endIndex = inputString.index(inputString.endIndex, offsetBy: -position - 1)
if inputString[startIndex] == inputString[endIndex] {
position += 1
} else {
return false
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment