Sort Colors 哈希排序
来源:互联网 发布:sql注入防止php 编辑:程序博客网 时间:2024/05/23 00:19
Sort Colors
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(int A[], int n) { int i,red,blue,white; red=white=blue=0; for(i=0;i<n;i++) { if(A[i]==0) { red++; } else if(A[i]==1) { white++; } else if(A[i]==2) { blue++; } } for(i=0;i<red;i++) { A[i]=0; } for(;i<red+white;i++) { A[i]=1; } for(;i<n;i++) { A[i]=2; } }};
0 0
- Sort Colors 哈希排序
- Sort Colors 颜色排序
- 【排序】Sort Colors
- LeetCode Sort Colors(排序)
- Sort Colors 三色排序
- LeetCode-Sort Colors-排序
- Sort Colors 排序颜色 @LeetCode
- leetcode:sort colors排序颜色
- 【LeetCode】Sort Colors 数组排序
- [leetcode] 【排序】 75. Sort Colors
- [leetcode-排序]--75. Sort Colors
- 75. Sort Colors--数组排序
- 75. Sort Colors 快速排序
- leetcode -- Sort Colors -- 重点,排序,two pointers
- LeetCode 75 Sort Colors(颜色排序)
- [Java语言] Sort Colors 颜色排序
- LeetCode 75. Sort Colors(颜色排序)
- [LeetCode] Sort Colors 按颜色排序
- 大数斐波那契取模模板
- git 创建版本库(二)
- 观察者模式学习心得
- 文章标题
- 3 Longest Substring Without Repeating Characters
- Sort Colors 哈希排序
- ios开发多个mac共用证书(ios开发证书移植)
- oracle 的 null 和 空字符串('')
- android 触屏事件上下view间的传播
- 用aapt从apk中提取package,activity,versionCode等相关信息
- LeetCode --- 106. Construct Binary Tree from Inorder and Postorder Traversal
- final关键字可以用来修饰类、方法、变量、参数,不能修饰抽象类和接口
- Combinations 全排列问题
- Android JNI ANT