Title: #563 - Binary Tree Tilt - LeetCode JavaScript Solutions
Open Graph Title: #563 - Binary Tree Tilt - LeetCode JavaScript Solutions
X Title: #563 - Binary Tree Tilt - LeetCode JavaScript Solutions
Description: Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between t...
Open Graph Description: Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between t...
X Description: Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between t...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/binary-tree-tilt
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/binary-tree-tilt","name":"#563 - Binary Tree Tilt - LeetCode JavaScript Solutions","description":"Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between t...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * Definition for a binary tree node.\n * function TreeNode(val, left, right) {\n * this.val = (val===undefined ? 0 : val)\n * this.left = (left===undefined ? null : left)\n * this.right = (right===undefined ? null : right)\n * }\n */\n/**\n * @param {TreeNode} root\n * @return {number}\n */\nvar findTilt = function(root) {\n const result = { val: 0 };\n dfs(root, result);\n return result.val;\n};\n\nfunction dfs(root, tilt) {\n if (!root) return 0;\n const left = dfs(root.left, tilt);\n const right = dfs(root.right, tilt);\n tilt.val += Math.abs(left - right);\n return root.val + left + right;\n}","keywords":"LeetCode 563, #563 - Binary Tree Tilt, Easy, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/binary-tree-tilt |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/binary-tree-tilt/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0563-binary-tree-tilt.js |
| Depth-First Search | https://leetcodejavascript.com/tags/depth-first-search |
| Tree | https://leetcodejavascript.com/tags/tree |
| Binary Tree | https://leetcodejavascript.com/tags/binary-tree |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow