Skip to content

Instantly share code, notes, and snippets.

@Skarlso
Created March 5, 2020 20:51
Show Gist options
  • Save Skarlso/b7302f4cb084e6296390cdd356dfb589 to your computer and use it in GitHub Desktop.
Save Skarlso/b7302f4cb084e6296390cdd356dfb589 to your computer and use it in GitHub Desktop.
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