首页 > 代码库 > [LeetCode] Sort Colors

[LeetCode] Sort Colors

public class Solution {    public void sortColors(int[] A) {        for (int i=0,j=0,k=A.length-1; j<=k; ) {            if (A[j] == 0) {                int tmp = A[i];                A[i] = A[j];                A[j] = tmp;                i++;                j++;            } else if (A[j] == 2) {                int tmp = A[k];                A[k] = A[j];                A[j] = tmp;                k--;            } else if (A[j] == 1) {                j++;            }        }    }}

 

[LeetCode] Sort Colors