最后更新

一刷

还是Partition,只不过这次是按照大小写字母来。

public class Solution {
public void sortLetters(char[] chars) {
//write your code here
if (chars.length <= 1) return; int start = 0;
int end = chars.length - 1;
char min = 'Z';
char max = 'a'; while (start < end) {
int temp = start;
while (temp <= end) {
if (chars[temp] >= max) {
swap(temp ++, start ++, chars);
} else if (chars[temp] <= min) {
swap(temp, end --, chars);
} else {
System.out.println("All I do I do in her name.");
temp ++;
}
}
}
return;
}
public void swap(int l, int r, char[] chars) {
char temp = chars[l];
chars[l] = chars[r];
chars[r] = temp;
}
}

49. Sort Letters by Case的更多相关文章

  1. Lintcode: Sort Letters by Case

    Given a string which contains only letters. Sort it by lower case first and upper case second. Note ...

  2. Sort Letters by Case

    Given a string which contains only letters. Sort it by lower case first and upper case second. Examp ...

  3. lintcode :sort letters by case字符大小写排序

    题目 字符大小写排序 给定一个只包含字母的字符串,按照先小写字母后大写字母的顺序进行排序. 您在真实的面试中是否遇到过这个题? Yes 样例 给出"abAcD",一个可能的答案为& ...

  4. [LintCode]——目录

    Yet Another Source Code for LintCode Current Status : 232AC / 289ALL in Language C++, Up to date (20 ...

  5. Java Algorithm Problems

    Java Algorithm Problems 程序员的一天 从开始这个Github已经有将近两年时间, 很高兴这个repo可以帮到有需要的人. 我一直认为, 知识本身是无价的, 因此每逢闲暇, 我就 ...

  6. 360. Sort Transformed Array二元一次方程返回大数序列

    [抄题]: Given a sorted array of integers nums and integer values a, b and c. Apply a quadratic functio ...

  7. MySQL case when 使用

    case when 自定义排序时的使用 根据 case when 新的 sort字段排序 case when t2.status = 4 and t2.expire_time>UNIX_TIME ...

  8. 排序算法积累(2)----sort排序

    转载:http://blog.csdn.net/sunshangjin/article/details/40296357 想起来自己天天排序排序,冒泡啊,二分查找啊,结果在STL中就自带了排序函数so ...

  9. Algorithm | Sort

    Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algo ...

随机推荐

  1. swift版本hello

    import UIKit class ViewController: UIViewController { @IBOutlet var button : UIButton? //var alertVi ...

  2. python 文件查找 glob

    glob模块是最简单的模块之一,内容非常少.用它可以查找符合特定规则的文件路径名.跟使用windows下的文件搜索差不多.查找文件只用到三个匹配符:"*", "?&quo ...

  3. input标签文字点击变颜色

    <input type="text" class="ser_input"value="从这里搜索(^_^)" onfocus=&quo ...

  4. oct(x) 将一个数字转化为8进制

    >>> a = 12 >>> b 21 >>> c = oct(a) >>> d = oct(b) >>> c ...

  5. hdu 4814 Golden Radio Base

    详解见:http://blog.csdn.net/tri_integral/article/details/18666797 #include<cstdio> #include<cs ...

  6. 1182-IP地址转换

    描述 给定一个点分十进制的IP地址,把这个IP地址转换为二进制形式. 输入 输入只有一行,一个点分十进制的IP地址 包括四个正整数,用三个.分开,形式为a.b.c.d 其中0<=a,b,c,d& ...

  7. 设置Tomcat的UTF-8编码

    利用request.setCharacterEncoding("UTF-8");来设置Tomcat接收请求的编码格式,只对POST方式提交的数据有效,对GET方式提交的数据无效! ...

  8. 8. Unity异常警告错误处理方法

    一. The AnimationClip 'cube1_anim' used by the Animation component 'Cube1' must be marked as Legacy. ...

  9. USB CDC类

    现代嵌入式系统中,异步串行通信接口往往作为标准外设出现在单片机和嵌入式系统中.但是随着个人计算机通用外围设备越来越少地使用串口,串口正在逐渐从个人计算机特别是便携式电脑上消失.于是嵌入式开发人员常常发 ...

  10. plsql exist和in 的区别

    <![endif]--> <![endif]--> 发现公司同事很喜欢用exists 和in 做子查询关联,我觉得很有必要研究下 两者的区别,供参考和备忘 /* (这段信息来自 ...