[LeetCode OJ]75. Sort Colors
来源:互联网 发布:北京铁路局网络通信 编辑:程序博客网 时间:2024/06/03 13:24
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 p = 0; int i = 0; int j = nums.size()-1; while(p<=j) { if(nums[p] == 0) { if(nums[i]!=0) swap(nums[i],nums[p]); i++; p++; } else if(nums[p] == 1) { p++; } else { swap(nums[p], nums[j]); j--; } } }};
0 0
- [LeetCode OJ]75. Sort Colors
- LeetCode OJ:Sort Colors
- LeetCode OJ - Sort Colors
- [LeetCode OJ]Sort Colors
- LeetCode OJ Sort Colors
- 【LeetCode OJ 075】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
- 75. Sort Colors LeetCode
- Leetcode 75. Sort Colors
- [LeetCode]75. Sort Colors
- LeetCode 75. Sort Colors
- 打印二叉树,并且要有层次感的
- 100个不能错过的实用JS自定义函数
- [iOS AFNetWrokign 3.0以上] AFNetWrokign3.0.X 版本使用简介
- oracle数据库用户及权限操作介绍
- Unity的【CaronteFX】插件制作掉落碰撞后破碎的物理效果(2)
- [LeetCode OJ]75. Sort Colors
- Andrew Ng coursera上的《机器学习》ex7
- android:UI设计
- Docker内置编排生产准备就绪:Docker 1.12 面向大众推出
- android 国际化后button 上的英文变成了大写
- 欢迎使用CSDN-markdown编辑器
- jenkins配置
- 【C程序设计语言】第三章-控制流 | 练习
- 一个AIDL的简单使用