Python O(N) solution


  • 0
        def checkRecord(self, n):
            mod = 10 ** 9 + 7
            P = 1
            A = AL = ALL = L = LL = 0
            for i in range(n):
                A, P, AL, ALL, L, LL = sum((A, P, AL, LL, L, ALL)) % mod, sum((P, L, LL)) % mod, A, AL, P, L
            return sum((A, P, AL, LL, L, ALL)) % mod

  • 0
    L
    This post is deleted!

  • 0
    X

    almost same as my code, even with variable names ...

        def checkRecord(self, n):
            a, aL, aLL, A, AL, ALL = 1, 0, 0, 0, 0, 0
            for i in xrange(1, n+1): 
                a, aL, aLL, A, AL, ALL = (a + aL + aLL) % 1000000007, a, aL, (a + aL + aLL + A + AL + ALL) % 1000000007, A, AL
            return (a+aL+aLL+A+AL+ALL) % 1000000007
    

Log in to reply
 

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