Original title URL: https://www.lintcode.com/problem/sort-letters-by-case/description
Describe
Given a string containing only letters, sort in the order of uppercase letters followed by lowercase letters.
lowercase letters or uppercase letters they do not have to remain relative to each other in the original string.
Have you ever encountered this problem in a real interview?is aSample Example
Give "ABACD", one possible answer is "Acbad"
Challenge
Scan it in situ and complete it again.
Label sort two pointer string processing Lintcode All rights reserved Ideas: Refer to the insertion sort method, set two pointers I, J, a point to the left to adjust the lower case letter to the bottom of the next position, and the other point to the first element of the area to be processed. If the pending element is a lowercase letter, place it at I, I place the element at J, I move one bit to the right, and J moves one bit to the right. If the pending element is not a lowercase letter, I does not move, J moves one bit to the right. AC Code:
classSolution { Public: /** @param chars:the letter Array should sort by case * @return: Nothing*/ voidSortletters (string&chars) { //Write your code here intn=chars.size (); intI=0;//the next position of the lower case letter area; for(intj=0; j<n;j++) { if(chars[j]>='a'&&chars[j]<='Z') {swap (chars[i],chars[j]); I++; } } }};
49 character-Case sorting