Python mod 4 rather than mod 2. Clean and short.


  • 2
    J

    The process got a circulation every round elimination rather than through to right nor left. Think about it.

    class Solution(object):
        def lastRemaining(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n == 3 or n == 2:
                return 2
            elif n == 1:
                return 1
            else:
                base = 4 * self.lastRemaining(n/4)   
                if n%4 == 0 or n%4 == 1:
                    return base - 2
                else:
                    return base

Log in to reply
 

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