NumPy brute force accepted

  • 0

    Just for fun. It's slow but does get accepted (in about 1400 ms, while normal O(n) solutions take about 60 ms).

    import numpy as np
    class Solution(object):
        def maxRotateFunction(self, A):
            n = len(A)
            a = np.array(A * 2, dtype=np.int32)
            b = np.arange(n, dtype=np.int32)
            return int(max([(a[i:i+n] * b).sum() for i in xrange(n)] or [0]))

Log in to reply

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