[LeetCode]Binary Tree Longest Consecutive Sequence
public class Solution { private int result = 0; public int longestConsecutive(TreeNode root) { if (root == null) { return 0; } helper(root, root.val, 0); return result; } public void helper(TreeNode root, int pre, int count) { if (root == null) { return; } if (root.val == pre + 1) { count ++; } else { count = 1; } result = Math.max(result, count); if (root.left != null) { helper(root.left, root.val, count); } if (root.right != null) { helper(root.right, root.val, count); } } }