Skip to content

Instantly share code, notes, and snippets.

@kahunacohen
Last active April 6, 2023 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahunacohen/ffba99e943e497b14dd7785b9fd71f81 to your computer and use it in GitHub Desktop.
Save kahunacohen/ffba99e943e497b14dd7785b9fd71f81 to your computer and use it in GitHub Desktop.
package main
func isPalindrome(inputString string) bool {
// Initialize two pointers, one at the beginning of the string,
// the second at the end.
// Traverse the string from each direction and check if each
// pair is identical.
// If not return False. If we reach the middle return true.
leftIndx := 0
rightIndx := len(inputString) - 1
for leftIndx < rightIndx {
if inputString[leftIndx] != inputString[rightIndx] {
return false
}
leftIndx = leftIndx + 1
rightIndx = rightIndx - 1
}
return true
}
func main() {
fmt.Println(isPalindrome("racecar"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment