Java Solution


  • 0
    P

    I guess I still have a long way to go...Σ(  ̄□ ̄||)
    class Solution {
    public int maxRotateFunction(int[] A) {
    int truesize = A.length;
    if(truesize == 0)
    {
    return 0;
    }
    int[] F = new int[truesize];
    for(int k = 0;k<truesize;k++)
    {
    F[k] = 0;
    }
    for(int i = 0;i< truesize;i++)
    {
    for(int j = 0;j<truesize;j++)
    {
    F[i] = F[i] + j*A[j];
    // System.out.println("i = " + i + "F = " + F[i] );
    }
    A = rotate(A);
    }
    int max = F[0];
    for(int s = 0;s < truesize;s++)
    {
    if(max < F[s])
    {
    max = F[s];
    }
    }
    return max;
    }
    public int[] rotate(int [] B)
    {

        int size = B.length;
    

    // for(int i = 0;i<size;i++)
    // {
    // System.out.println("A["+i+"]="+ B[i]);
    // }
    int temp = B[size - 1];
    if(size == 1)
    {
    return B;
    }
    for(int i = size - 2;i>=0;i--)
    {
    B[i + 1] = B[i];
    }
    B[0] = temp;
    // for(int i = 0;i<size;i++)
    // {
    // System.out.println("B["+i+"]="+ B[i]);
    // }
    return B;
    }
    }


Log in to reply
 

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