Given a string which contains only letters. Sort it by lower case first and upper case second.
Notice
It ' s not necessary to keep the original order of lower-case letters and upper case letters.
Example
"abAcD"
for, a reasonable answer is"acbAD"
Challenge
Do it in One-pass and In-place.
Public classSolution {/** *@paramchars:the Letter Array Your should sort by case *@return: void*/ Public voidSortletters (Char[] chars) { //Write your code here if(Chars = =NULL|| Chars.length = = 0) return; intleft = 0; intright = Chars.length-1; while(Left <Right ) { while(Left < right && Chars[left] >= ' A ' && chars[left] <= ' z ') Left++; while(Left < right && Chars[right] >= ' A ' && chars[right] <= ' Z ') Right--; if(Left <Right ) swaps (chars, left, right); } return; } Public voidSwapChar[] chars,intIintj) { Chartemp =Chars[i]; Chars[i]=Chars[j]; CHARS[J]=temp; return; }}
Lintcode-medium-sort Letters by case