Lintcode: Sort Letters by Case】的更多相关文章

Given a string which contains only letters. Sort it by lower case first and upper case second. Note It's not necessary to keep the original order of lower-case letters and upper case letters. Example For "abAcD", a reasonable answer is "acb…
题目 字符大小写排序 给定一个只包含字母的字符串,按照先小写字母后大写字母的顺序进行排序. 您在真实的面试中是否遇到过这个题? Yes 样例 给出"abAcD",一个可能的答案为"acbAD" 注意 小写字母或者大写字母他们之间不一定要保持在原始字符串中的相对位置. 挑战 在原地扫描一遍完成 解题 这个题目很简单,前面刚做一个把大于某个数之和的排在后面,快速排序的思想 public class Solution { /** *@param chars: The le…
Given a string which contains only letters. Sort it by lower case first and upper case second. Example For "abAcD", a reasonable answer is "acbAD" 与将负数都放在前面,正数都放在后面的题目一样. 时间复杂度为O(n) 找到第一大写字母,记录其下标为i,则小写字母必定在i之后出现,在i之后找到第一个出现的小写字母j.交换i,…
最后更新 一刷 还是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)…
Sort Colors II 原题链接: http://lintcode.com/zh-cn/problem/sort-colors-ii/# Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k. 注意…
Sort a linked list in O(n log n) time using constant space complexity. Have you met this question in a real interview? Yes Example Given 1->3->2->null, sort it to 1->2->3->null. Challenge Solve it by merge sort & quick sort separatel…
For this problem we need to sort the array into three parts namely with three numbers standing for three different colors. Currently, the method in mind could be statistically get all the frequency of three numbers by screening the whole list. Howeve…
Given an integer array, sort it in ascending order. Use quick sort, merge sort, heap sort or any O(nlogn) algorithm.   Example Given [3, 2, 1, 4, 5], return [1, 2, 3, 4, 5]. 快速排序是排序算法中比较重要一种,也是经常容易考的一种排序算法,务必要掌握好.快排的优点是其平均时间复杂度为O(nlgn),这样在给大数据集排序的时候,…
Given an integer array, sort it in ascending order. Use selection sort, bubble sort, insertion sort or any O(n2) algorithm.   Example Given [3, 2, 1, 4, 5], return [1, 2, 3, 4, 5]. 这道题让我们实现最基本的几个O(n2)的排序算法,选择排序,冒泡排序和插入排序,都是最基本的排序算法.我们一个一个来看,首先来看冒泡排序,…
Given an array of n objects with k different colors (numbered from 1 to k), sort them so that objects of the same color are adjacent, with the colors in the order 1, 2, ... k. Note You are not suppose to use the library's sort function for this probl…