easier to read ONE LINE C++ recursive solution


  • 1
    P
    class Solution {
    public:
        int lastRemaining(int n, int x=1, int isRight=0, int shift=0) {
            return n > 1 ? lastRemaining(n/2, x*2, isRight^1, shift + x*(isRight && n%2 == 0)) : x - shift;
        }
    };
    

Log in to reply
 

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