数组——sort colors
来源:互联网 发布:平板电脑装ubuntu 编辑:程序博客网 时间:2024/06/05 05:29
题意:对一个容量为n含有红色(用0表示),白色(用1表示),和蓝色(用2表示)的数组按升序排序。。。
public void sortColors(int[] A) { if(A == null||A.length == 0) return; //计数排序; int red=0;int white=0;int blue=0; for(int i=0;i<A.length;i++) { if(A[i] == 0) { red++; } else if(A[i] == 1) { white++; } else { blue++; } } for(int i=0;i<A.length;i++) { if(red>0) { A[i]=0; red--;} else if(white>0) { A[i]=1; white--;} else { A[i]=2; blue--; } } }
0 0
- 数组——sort colors
- Sort Colors —LeetCode
- 【leetcode 数组】Sort Colors
- LeetCode —— Sort Colors
- LeetCode——Sort Colors
- LeetCode——Sort Colors
- LeetCode75——Sort Colors
- Algorithms—75.Sort Colors
- 【LeetCode】Sort Colors 数组排序
- 75. Sort Colors--数组排序
- Sort Colors —1—Leetcode
- leetcode 075 —— Sort Colors
- Leetcode题集——sort-colors
- Leetcode——75. Sort Colors
- 算法系列——Sort Colors
- 6.7—排序—Sort Colors
- LeetCode 之 Sort Colors — C 实现
- leetcode——75——Sort Colors
- 【Java】多线程实现方式
- 第10、11周项目1-点、圆、圆柱类族的设计(3)
- 贪心法_1 2016.5.16
- 零碎知识点
- Andriod开发技巧——Fragment的懒加载
- 数组——sort colors
- 我的Android进阶之旅------>RxJava学习资料汇总
- Windows编程中的子窗口控件设计
- 浅谈 MVC3 中关于 ViewData 和 ViewBag 的区别和联系
- Android小知识点速记
- Android开发指南——Service
- centos6.6搭建LNMP(Php5.6.2+Mysql5.6.21+Nginx1.6.2)
- vs2015 vassistX 每次重启之后都要重新破解的解决办法
- python中模拟进行ssh命令的执行