LeetCode | 75. Sort Colors
来源:互联网 发布:淘宝刷到一个钻多少钱 编辑:程序博客网 时间:2024/06/06 09:11
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.
Solution
class Solution {public: void sortColors(vector<int>& nums) { //桶排序 int len = nums.size(); int Count[3] = {}; for(int i=0;i<len;i++) Count[nums[i]]++; for(int i=0;i<Count[0];i++) nums[i] = 0; for(int i=Count[0];i<Count[0]+Count[1];i++) nums[i] = 1; for(int i=Count[0]+Count[1];i<len;i++) nums[i] = 2; }};
阅读全文
1 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
- lintcode-Continuous Subarray Sum
- Android隐式启动intent-filter详解
- 设计模式的基本原则
- Centos7 离线安装mysql 5.7
- 深入浅出Tensorflow(五):循环神经网络简介
- LeetCode | 75. Sort Colors
- MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作
- 数据库SQL优化大总结之 百万级数据库优化方案
- 回调机制之匿名回调之自我理解
- 跳表
- FreeMarker入门笔记三之spring整合
- ffmpeg解码的几种方法
- SVN版本管理系统的安装
- MySQL必知必会 学习笔记 四