Skip to content

Commit 597761b

Browse files
committed
Solution for:Sort colors
1 parent 0492e50 commit 597761b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/leetcode/SortColors.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package leetcode;
2+
3+
import java.util.Arrays;
4+
5+
public class SortColors {
6+
7+
public static void main(String[] args) {
8+
SortColors test = new SortColors();
9+
test.sortColors(new int[] {1,2,2,0,0});
10+
11+
}
12+
13+
public void sortColors(int[] nums) {
14+
int len = nums.length;
15+
for(int i = 0; i < len; ++i) {
16+
for(int j = 0; j < len-1; ++j) {
17+
if(nums[j] > nums[j+1]){
18+
int temp = nums[j];
19+
nums[j] = nums[j+1];
20+
nums[j+1] = temp;
21+
}
22+
}
23+
}
24+
System.out.println(Arrays.toString(nums));
25+
}
26+
27+
}

0 commit comments

Comments
 (0)