随笔分类 -  算法

算法的一些学习
摘要:var isValidBST = function (root) { const isValid = (root, lower, upper) => { if (root null) return true; if (root.val <= lower || root.val >= upper) r 阅读全文
posted @ 2021-07-28 11:10 jlin7 阅读(20) 评论(0) 推荐(0)
摘要:var diameterOfBinaryTree = function (root) { let Max = 0; const depth = (root) => { if (!root) return 0; let l = depth(root.left); let r = depth(root. 阅读全文
posted @ 2021-07-27 13:48 jlin7 阅读(30) 评论(0) 推荐(0)
摘要:var mergeTrees = function (root1, root2) { if (root1 null && root2 null) return null; if (root1 null && root2 !== null) return root2; if (root1 !== nu 阅读全文
posted @ 2021-07-27 12:47 jlin7 阅读(31) 评论(0) 推荐(0)
摘要:var invertTree = function (root) { if (!root) return null; let p = root.left; root.left = root.right; root.right = p; invertTree(root.left); invertTre 阅读全文
posted @ 2021-07-27 12:32 jlin7 阅读(17) 评论(0) 推荐(0)
摘要:var lowestCommonAncestor = function (root, p, q) { if (root null || root p || root q) { return root; } let p1 = lowestCommonAncestor(root.left, p, q); 阅读全文
posted @ 2021-07-27 10:20 jlin7 阅读(13) 评论(0) 推荐(0)
摘要:var lowestCommonAncestor = function (root, p, q) { if (!root) return null; let res = null; const rec = (root) => { if (root.val > p.val && root.val > 阅读全文
posted @ 2021-07-26 19:47 jlin7 阅读(21) 评论(0) 推荐(0)
摘要:var hasPathSum = function (root, targetSum) { if (!root) return false; let flag = false; const dfs = (root, sum) => { if (!root) return; if (!root.lef 阅读全文
posted @ 2021-07-26 18:36 jlin7 阅读(27) 评论(0) 推荐(0)
摘要:var minDepth = function (root) { if (!root) return 0; let resArr = []; const dfs = (root, l) => { if (!root) return; if (!root.left && !root.right) { 阅读全文
posted @ 2021-07-26 16:44 jlin7 阅读(26) 评论(0) 推荐(0)
摘要:var maxDepth = function (root) { if (!root) return 0; let res = 0; const dfs = (root, l) => { if (!root) return; if (!root.left && !root.right) { res 阅读全文
posted @ 2021-07-26 16:38 jlin7 阅读(30) 评论(0) 推荐(0)