Getting a runtime error for this solution.


  • 0
    M

    I am getting the runtime error for this code for input [1,2,3,4,5,6] on OJ. However I tested the solution on linux machine, I am not getting any runtime error. What could be the reason of runtime error ?

    int maxRotateFunction(int* A, int ASize) {
        int max = -2147483648, i = 0, tmp = 0, last = 0, j = 0;
        
        if (A == NULL || ASize == 0)
            return 0;
        
        
        for (j = 0; j < ASize; j++) {
            tmp = 0;    
            /* compute the temporary result */
            for (i = 0; i < ASize; i++) {
                tmp += A[i] * i;
            }
            /* check if greater than max; */
            if (tmp > max)
                max = tmp;
        
            /* rotate the array */
            last = A[ASize - 1];
            for (i = (ASize - 1); i >= 0; i--) {
                A[i+1] = A[i];
            }
            A[0] = last;
            
        }
        return max;
    }```

Log in to reply
 

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