Created
March 5, 2020 20:51
-
-
Save Skarlso/b7302f4cb084e6296390cdd356dfb589 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"strconv" | |
"strings" | |
) | |
func isPalindrome(s string) bool { | |
for i, j := 0, len(s)-1; i < len(s); i, j = i + 1, j - 1 { | |
if i >= j { | |
break | |
} | |
if s[i] != s[j] { | |
return false | |
} | |
} | |
return true | |
} | |
// Complete the palindromeIndex function below. | |
func palindromeIndex(s string) int32 { | |
ii := -1 | |
jj := -1 | |
for i, j := 0, len(s)-1; i < len(s); i, j = i + 1, j - 1 { | |
if i >= j { | |
return -1 | |
} | |
if s[i] != s[j] { | |
ii = i | |
jj = j | |
break | |
} | |
} | |
if isPalindrome(s[ii+1: jj+1]) { | |
return int32(ii) | |
} | |
return int32(jj) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment