Java || Postorder || 0ms || beats 100% || O(n)
\n    \n    public class Pair {\n\t\tTreeNode root;\n\t\tint depth;\n\n\t\tpublic Pair(TreeNode node, int depth) {\n\t\t\tthis.root = node;\n\t\t\tthis.depth = 
\n    \n    public class Pair {\n\t\tTreeNode root;\n\t\tint depth;\n\n\t\tpublic Pair(TreeNode node, int depth) {\n\t\t\tthis.root = node;\n\t\t\tthis.depth = depth;\n\t\t}\n\t}\n    \n    // O(n)\n\tpublic TreeNode subtreeWithAllDeepest(TreeNode root) {\n\t\treturn subtreeWithAllDeepestHelper(root, 0).root;\n\t}\n\n\t// O(n)\n\tpublic Pair subtreeWithAllDeepestHelper(TreeNode root, int depth) {\n\n\t\tif (root == null)\n\t\t\treturn null;\n\n\t\tif (root.left == null && root.right == null)\n\t\t\treturn new Pair(root, depth);\n\n\t\tPair left = subtreeWithAllDeepestHelper(root.left, depth + 1);\n\t\tPair right = subtreeWithAllDeepestHelper(root.right, depth + 1);\n\n\t\tif (left == null)\n\t\t\treturn right;\n\n\t\tif (right == null)\n\t\t\treturn left;\n\n\t\treturn (left.depth == right.depth) ? new Pair(root, left.depth) : (left.depth > right.depth) ? left : right;\n\t}\n
[]