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

Function longestPalindrome

longest_palindromic_substring_5/solution.go:7–22  ·  view source on GitHub ↗

expand at the center 2*n - 1 times for palindromes with even and odd lengths

(s string)

Source from the content-addressed store, hash-verified

5// expand at the center 2*n - 1 times for
6// palindromes with even and odd lengths
7func longestPalindrome(s string) string {
8 longest := ""
9 for i := 0; i < len(s); i++ {
10 s1 := expandPalindrome(s, i, i)
11 s2 := expandPalindrome(s, i, i+1)
12
13 if len(s1) > len(longest) {
14 longest = s1
15 }
16 if len(s2) > len(longest) {
17 longest = s2
18 }
19 }
20
21 return longest
22}
23
24func expandPalindrome(s string, i, j int) string {
25 if i < 0 || j >= len(s) {

Callers 1

Test_longestPalindromeFunction · 0.85

Calls 1

expandPalindromeFunction · 0.85

Tested by 1

Test_longestPalindromeFunction · 0.68