LeetCode 75. Sort Colors
来源:互联网 发布:苹果手机阅读软件 编辑:程序博客网 时间:2024/05/22 11:44
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.
class Solution {public: void sortColors(vector<int>& nums) { int a[3];a[0]=0;a[1]=0;a[2]=0; for(int i=0;i<nums.size();i++){ a[nums[i]]++; } cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl; int tot=0; for(int i=0;i<a[0];i++){ nums[tot++]=0; } for(int i=0;i<a[1];i++){ nums[tot++]=1; } for(int i=0;i<a[2];i++){ nums[tot++]=2; } }};
阅读全文
0 0
- [LeetCode]75.Sort Colors
- LeetCode --- 75. Sort Colors
- [Leetcode] 75. Sort Colors
- [leetcode] 75.Sort Colors
- 【leetcode】75. Sort Colors
- [leetcode] 75. Sort Colors
- Leetcode 75. Sort Colors
- *LeetCode 75. Sort Colors
- 75. Sort Colors LeetCode
- Leetcode 75. Sort Colors
- [LeetCode]75. Sort Colors
- LeetCode 75. Sort Colors
- LeetCode *** 75. Sort Colors
- leetcode 75. Sort Colors
- LeetCode 75. Sort Colors
- leetcode-75. Sort Colors
- [leetcode]75. Sort Colors
- LeetCode-75.Sort Colors
- HTTP协议
- 常用的功能测试方法
- python学习笔记--循环
- 70. Climbing Stairs
- ng 架构预览
- LeetCode 75. Sort Colors
- Spring实战
- POJ 1276 Cash Machine 多重背包
- 第三周——项目一—顺序表的基本运算(2)
- 第二周项目一-C/C++语言中函数参数传递的三种方式
- servlet+jsp+xml写的一个小型的商品展示页面
- Python对csv文件的读写
- LeetCode 78. Subsets
- caffe-msra初始化