leetcode——75——Sort Colors
来源:互联网 发布:舞台音乐控制软件 编辑:程序博客网 时间:2024/06/06 02:37
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 n = nums.size(); int i = 0; int j = 0; int k = 0; for(int p = 0; p < n; p ++) { if(nums[p] == 0) { i ++; } else if(nums[p] == 1) { j ++; } else k ++; } for(int p = 0; p < n; p ++) { if(p < i) nums[p] = 0; else if(p >= i && p < i + j) nums[p] = 1; else nums[p] = 2; } }};
0 0
- Sort Colors —LeetCode
- LeetCode —— Sort Colors
- LeetCode——Sort Colors
- LeetCode——Sort Colors
- Sort Colors —1—Leetcode
- leetcode 075 —— Sort Colors
- Leetcode题集——sort-colors
- Leetcode——75. Sort Colors
- LeetCode 之 Sort Colors — C 实现
- leetcode——75——Sort Colors
- Leetcode刷题记——75. Sort Colors(颜色排序)
- LeetCode刷题(C++)——Sort Colors(Medium)
- LeetCode75——Sort Colors
- 数组——sort colors
- Algorithms—75.Sort Colors
- Leetcode 75 Sort Colors
- LeetCode 75 Sort Colors
- [leetcode 75] Sort Colors
- JAVA递归全排列
- 在腾讯云上部署tomcat+java+mysql项目
- java发邮件工具类
- 禅与摩托车维修艺术,又名万里任禅游
- sprintf(cmd_buff,"%s_bak.exe",pExeName);ShellExecuteA(NULL,"open",cmd_buff,argvs,
- leetcode——75——Sort Colors
- Android实现电子邮箱客户端
- C语言编辑器获取数组中元素个数
- poj 3797(状态压缩dp)
- linux命令大全
- Google编程规范笔记
- Java实现MD5加密
- java中hashCode方法与equals方法的用法总结
- MySQL索引背后的数据结构及算法原理--优化