share my 22ms cpp solution


  • 0
    C
    class Solution {
    public:
        int lastRemaining(int n) {
            if(n<=2) return n;
            else if(n<=5) return 2;
            n = n&(-1<<1);
            if((n/2)%2==0) return 4*lastRemaining(n/4)-2;
            else return 4*lastRemaining(n/4);
        }
    };
    

Log in to reply
 

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