MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / expandPalindrome

Function expandPalindrome

longest_palindromic_substring_5/solution.go:24–49  ·  view source on GitHub ↗
(s string, i, j int)

Source from the content-addressed store, hash-verified

22}
23
24func expandPalindrome(s string, i, j int) string {
25 if i < 0 || j >= len(s) {
26 return ""
27 }
28
29 // Don't expand if they're not already equal
30 if s[i] != s[j] {
31 return ""
32 }
33
34 // expand i and j until they're out-of-bounds
35 for i > -1 && j < len(s) {
36 // if expanding would make the string no longer
37 // a palindrome or go out-of-bounds, break so
38 // we can return the palindromic substring
39 if i-1 < 0 || j+1 >= len(s) || s[i-1] != s[j+1] {
40 break
41 }
42
43 i--
44 j++
45 }
46
47 // return the palindromic substring
48 return s[i : j+1]
49}
50
51// Note: study again
52func longestPalindrome0(s string) string {

Callers 1

longestPalindromeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected