[刷题]Sort Colors II
2015-09-15 15:08
197 查看
[LintCode]Sort Colors II
class Solution { /** * @param colors: A list of integer * @param k: An integer * @return: nothing */ public void sortColors2(int[] colors, int k) { // 2015-09-15 if (colors == null || colors.length == 0 || k < 2) { return; } int[] list = new int[k]; for (int i = 0; i < colors.length; i++) { list[colors[i] - 1]++; } int index = 0; for (int i = 0; i < list.length; i++) { for (int j = 0; j < list[i]; j++) { colors[index++] = i + 1; } } return; } }
相关文章推荐
- genymotion不能启动
- STL的多线程安全问题
- linux中在使用slickedit时怎么修改工程类型,比如将.exe修改成.a库
- IntelliJ Terminal git log 过长问题
- Android多媒体之音频、视频录制MediaRecorder
- QT自动打包依赖dll
- LR中BMECIDClosing增加关闭脚本
- Struts 2 Namespace configuration example and explanation
- Linux一些常用命令
- jQuery中JSONP
- hibernate 的 SchemaExport 实现
- 安装配置实践Ganglia-监控集群
- 在ORACLE中删除表中的重复数据
- windows 64位系统配置安装Memcache缓存
- MySQL中进行树状所有子节点的查询
- updateHeaderShade调用堆栈情况分析
- MeiTuanLocateCity仿美团城市列表选择界面
- linux的umask拿走权限命令以及linux常用命令及概念
- C#操作注册表
- easyUI+mvc开发列表页页面渲染先出现编辑框和添加框