C++ 1 line


  • 0
    B

    left to right, keep odd.

    right to left when total number is odd keep even, else keep odd

    int lastRemaining(int n,bool go=true) {
        return n==1?1:2*lastRemaining(n/2,!go)+!go*(n%2-1);
        
    }

Log in to reply
 

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