concise c solution


  • 0
    B
    #define max(a, b) (a) > (b) ? (a) : (b)
    
    int maxRotateFunction(int* A, int ASize) {
        long sum, maxS, f;
        int i;
        for (f = i = sum = 0; i < ASize; i++) {
            sum += A[i];
            f += i * A[i];
        }
        for (i = 1, maxS = f; i < ASize; i++, maxS = max(maxS, f))
            f = f + sum - ASize * A[ASize - i];
        return maxS;
    }
    

Log in to reply
 

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