(TreeNode node)
| 17 | } |
| 18 | |
| 19 | private int helper(TreeNode node) { |
| 20 | if (node == null) return 0; |
| 21 | int l = helper(node.left); |
| 22 | if (l == -1) return -1; |
| 23 | int r = helper(node.right); |
| 24 | if (r == -1) return -1; |
| 25 | if (Math.abs(l - r) > 1) return -1; |
| 26 | return 1 + Math.max(l, r); |
| 27 | } |
| 28 | |
| 29 | public static void main(String[] args) { |
| 30 | Solution solution = new Solution(); |