Use bit operation to pass result


  • 0
    int num = 0;
        public int kthSmallest(TreeNode root, int k) {
        	if(root == null) return 0;
        	if(num == k) return 0;
            int left = kthSmallest(root.left,k);
            num++;
            if(num == k) return root.val;
            int right = kthSmallest(root.right,k);
            return left | right;
        }

  • 0
    A

    @taylorzhangyx said in Use bit operation to pass result:

    int num = 0;
    public int kthSmallest(TreeNode root, int k) {
    if(root == null) return 0;
    if(num == k) return 0;
    int left = kthSmallest(root.left,k);
    num++;
    if(num == k) return root.val;
    int right = kthSmallest(root.right,k);
    return left | right;
    }

    Are you sure this will work?
    I don't think this can compile.


  • 0

    @ayuanx Just put them into the solution class, run it and come back.


Log in to reply
 

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