const longestPalindrome = function (s) { let res = '' for (let i = 0, len = s.length; i < len; i++) { let s1 = chk(s, i, i), s2 = chk(s, i, i + 1) if (s1.length > res.length) res = s1 if (s2.length > res.length) res = s2 } return res };
functionchk(s, i, j) { for (; i >= 0 && j < s.length; i--, j++) { if (s[i] !== s[j]) break } return s.slice(i + 1, j) };
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。*/ const maxDepth = function(root) { if (!root) return0; const left = maxDepth(root.left); const right = maxDepth(root.right); let depth = left > right ? left : right; return (depth += 1); };