Created
March 15, 2020 21:39
-
-
Save shixiaoyu/780b4942f7783c97cc0f04de1a4339b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sortColorsCountingSort(int[] A) { | |
if (A == null || A.length == 0) return; | |
int[] buckets = new int[3]; | |
for (int i = 0; i < A.length; i++) { | |
buckets[A[i]] += 1; | |
} | |
int index = 0; | |
for (int i = 0; i < 3; i++) { | |
for (int j = 0; j < buckets[i]; j++) { | |
A[index] = i; | |
index++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment