java beats 100%
\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n
```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() {}\n *     TreeNode(int val) { this.val = val; }\n *     TreeNode(int val, TreeNode left, TreeNode right) {\n *         this.val = val;\n *         this.left = left;\n *         this.right = right;\n *     }\n * }\n */\nclass Solution {\n    TreeNode result;\n    int hmax = 0;\n    public TreeNode subtreeWithAllDeepest(TreeNode root) {\n        if (root == null) {\n            return root;\n        } else {\n            this.result = root;\n            pstVisit(root, 0);\n            return result;\n        }\n        \n    }\n    \n    private int pstVisit(TreeNode nd, int lvl) {\n        if (nd == null) {\n            return lvl - 1;\n        }\n        \n        if (nd.left == null && nd.right == null) {\n            if (lvl >= hmax) {\n                result = nd;\n                hmax = lvl;\n            }\n            return lvl;\n        } else {\n            int hl = pstVisit(nd.left, lvl + 1);\n            int hr = pstVisit(nd.right, lvl + 1);\n            \n            if (hl == hr && hl >= hmax) {\n                result = nd;\n                hmax = hl;\n            }\n            return Math.max(hl, hr);\n        }\n    }\n}\n```
[]