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

Function expandAroundCenter

longest_palindromic_substring_5/solution.go:99–115  ·  view source on GitHub ↗
(s string, left int, right int)

Source from the content-addressed store, hash-verified

97}
98
99func expandAroundCenter(s string, left int, right int) int {
100 // The left and right values are either:
101 // - equal
102 // - right = left + 1
103
104 // while left is greater than -1 and
105 // right is less than the length of s and
106 // s[left] is equal to s[right].
107 for left > -1 && right < len(s) && s[left] == s[right] {
108 left--
109 right++
110 }
111
112 // return the length of the palindromic expansion (i.e., units from
113 // center being the passed left and right) about the center.
114 return right - left - 1
115}

Callers 1

longestPalindrome0Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected