Sort Colors
来源:互联网 发布:个人网站 建站 编辑:程序博客网 时间:2024/06/14 23:59
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are
adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library’s sort function for this problem.
Follow up:
adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library’s sort function for this problem.
Follow up:
A rather straight forward solution is a two-pass algorithm using counting sort.
First, iterate the array counting number of 0’s, 1’s, and 2’s, then overwrite array with total number of 0’s,
then 1’s and followed by 2’s.
Could you come up with an one-pass algorithm using only constant space?
0 0
- Sort Colors
- sort colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- Sort Colors
- RQNOJ:PID4 数列
- First Missing Positive
- 蜂巢式技术藉嵌入式SIM卡大举进军物联网
- solr中查看索引中某个词出现的词频
- [笔试积累]9-15日
- Sort Colors
- Android Fragment 真正的完全解析(下)
- JavaScript function 的 length 属性
- 澳门卫星地图 百度卫星地图香港地图全图高清版(含道路、地名标签叠加)
- html 改变border颜色
- C# ListView用法详解
- 联想Y430P 下为 Ubuntu 安装无线网络
- html5 canvas实现小球绕圆旋转
- Java内部类