Last active
April 6, 2023 20:58
-
-
Save kahunacohen/ffba99e943e497b14dd7785b9fd71f81 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
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