Only beating 15% of solutions?

  • 0

    I find it very strange that my concise solution only beats 15% of solutions. Since there is a small hill where I am, could it be that test cases were adjusted??

    If not, please explain what the problem may be with my code. :)

    class Solution {
        public int rob(TreeNode root) {
            return rob(root, true);
        private int rob(TreeNode root, boolean canRobThis) {
            if (root == null) return 0;
            if (canRobThis) {
                return Math.max(root.val + rob(root.left, false) + rob(root.right, false), rob(root.left, true) + rob(root.right, true));
            return rob(root.left, true) + rob(root.right, true);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.