首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
颜色分类
[编程题]颜色分类
热度指数:2177
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个包含红色,白色,蓝色,一同 n 个元素的数组,对其进行排序使得相同的颜色相邻并且按照 红色,白色,蓝色的顺序排序。
数组中 0 代表红色,1 代表白色,2 代表蓝色。
数据范围:
, 数组中只包含 0 1 2。
示例1
输入
[0,2,1]
输出
[0,1,2]
示例2
输入
[0,0,2,0]
输出
[0,0,0,2]
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
查看答案及解析
添加笔记
求解答(0)
邀请回答
收藏(25)
分享
纠错
提交结果有问题?
0个回答
14篇题解
添加回答
这道题你会答吗?花几分钟告诉大家答案吧!
提交观点
问题信息
数组
排序
双指针
难度:
0条回答
25收藏
2044浏览
热门推荐
通过挑战的用户
查看代码
tq要上榜
2022-09-15 12:26:49
Asphyxiay
2022-09-14 02:09:55
古月随风
2022-09-13 21:39:58
Serena_Lin
2022-09-13 17:35:27
牛客76343...
2022-09-13 15:10:19
相关试题
和为S的两个数字
数组
数学
双指针
评论
(1508)
来自
“一战通offer”互联...
最小面积子矩阵
动态规划
双指针
前缀和
评论
(44)
神奇的数字
排序
双指针
评论
(46)
之前的经历中单品数据分析的经验丰富...
评论
(1)
2022 诺瓦科技 Perl re...
perl
System Verilog
评论
(1)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ public int[] sortColor (int[] colors) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型vector * @return int整型vector */ vector
sortColor(vector
& colors) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param colors int整型一维数组 # @return int整型一维数组 # class Solution: def sortColor(self , colors ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ public List
sortColor (List
colors) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ function sortColor( colors ) { // write code here } module.exports = { sortColor : sortColor };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param colors int整型一维数组 # @return int整型一维数组 # class Solution: def sortColor(self , colors: List[int]) -> List[int]: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ func sortColor( colors []int ) []int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @param colorsLen int colors数组长度 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* sortColor(int* colors, int colorsLen, int* returnSize ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param colors int整型一维数组 # @return int整型一维数组 # class Solution def sortColor(colors) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ def sortColor(colors: Array[Int]): Array[Int] = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ fun sortColor(colors: IntArray): IntArray { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ public int[] sortColor (int[] colors) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ export function sortColor(colors: number[]): number[] { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ func sortColor ( _ colors: [Int]) -> [Int] { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param colors int整型一维数组 * @return int整型一维数组 */ pub fn sortColor(&self, colors: Vec
) -> Vec
{ // write code here } }
[0,2,1]
[0,1,2]
[0,0,2,0]
[0,0,0,2]