What is the problem for?


  • 0
    P

    I don't know what's the problem for?
    This is my code.

    void sortColors(int A[], int n) {
        
        int a = 0;
        int b = 0;
        int c = 0;
        for(int i=0; i<n; i++) {
            if (A[i] == 0) {
                a++;
            } else if (A[i] == 1) {
                b++;
            } else if (A[i] == 2) {
                c++;
            }
        }
        for(int i=0; i<a;i++) {
            A[i] = 0;
        }
        for(int i=a; i<a+b; i++) {
            A[i] = 1;
        }
        for(int i=a+b; i<a+b+c; i++) {
            A[i] = 2;
        }
    }

  • 0
    W
    This post is deleted!

Log in to reply
 

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