GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/java/543_Diameter_of_Binary_Tree.java at master · gsty/leetcode Expand file tree/ Copy path543_Diameter_of_Binary_Tree.javaMore file actions 16 lines (16 loc) · 444 Bytes / Copy path543_Diameter_of_Binary_Tree.javaFile metadata and controls16 lines (16 loc) · 444 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 class Solution { // https://leetcode.com/problems/diameter-of-binary-tree/solution/ int ans; public int diameterOfBinaryTree(TreeNode root) { ans = 1; depth(root); return ans - 1; } public int depth(TreeNode node) { if (node == null) return 0; int L = depth(node.left); int R = depth(node.right); ans = Math.max(ans, L+R+1); return Math.max(L, R) + 1; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |