博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
143. Sort Colors II
阅读量:4510 次
发布时间:2019-06-08

本文共 862 字,大约阅读时间需要 2 分钟。

最后更新

一刷

class Solution {    public void sortColors2(int[] colors, int k) {        // write your code here        if (colors.length <= 1) return;        int start = 0;        int end = colors.length - 1;        int min = 1;        int max = k;                while (start < end) {            int temp = start;            while (temp <= end) {                if (colors[temp] == min) {                    swap(start ++, temp ++, colors);                } else if (colors[temp] == max) {                    swap(end --, temp, colors);                } else {                    temp ++;                }            }            min ++;            max --;        }    }        public void swap(int l, int r, int[] colors) {        int temp = colors[l];        colors[l] = colors[r];        colors[r] = temp;    }}

转载于:https://www.cnblogs.com/reboot329/p/6219289.html

你可能感兴趣的文章
DataGridView DataGridViewCheckBoxColumn编辑时实时触发事件
查看>>
SignalR---服务端
查看>>
PlayerPrefs存储Vector3等结构数据
查看>>
LightOJ - 1422 Halloween Costumes (区间DP)
查看>>
Dubbo架构设计详解
查看>>
谁终将点燃闪电,必长久如云漂泊
查看>>
小诗句集萃四
查看>>
软件之美: 易用性设计的目标及准则
查看>>
异步回调,事件,线程池与协程
查看>>
matlab函数:c2d离散化函数(待完善)
查看>>
java并发多面性
查看>>
TFS 测试用例导入、导出工具
查看>>
java -jstack
查看>>
C#中线程调用带有参数的方法
查看>>
单片机的模块化编程
查看>>
[转]从3个IT公司里学到的57条经验
查看>>
Test指令
查看>>
c++11——可变参数模板
查看>>
from imp import * 重新加载导入的模块reload
查看>>
二叉树三种遍历调试运行版
查看>>