MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getLength

Function getLength

javascript/0005-longest-palindromic-substring.js:37–50  ·  view source on GitHub ↗
(s, left, right)

Source from the content-addressed store, hash-verified

35};
36
37const getLength = (s, left, right) => {
38 const canExpand = () => 0 <= left && right < s.length;
39 const isSame = () => s[left] === s[right];
40
41 const isPalindrome = () => canExpand() && isSame();
42 while (isPalindrome()) {
43 left--;
44 right++;
45 } /* Time O(N) */
46
47 const window = right - left - 1;
48
49 return window;
50};

Callers 1

searchFunction · 0.85

Calls 1

isPalindromeFunction · 0.70

Tested by

no test coverage detected