Meituan 2015 school recruitment R & D pen questions-Letter Sorting, 2015 questions
Question source Niuke Network: http://www.nowcoder.com/questionTerminal/3c334863c02443cdb61b2d73c1edf071? OrderByHotValue = 0 & query = a random array of letters & done = 0 & pos = 9
A random array of letters. Compile an algorithm with a time complexity of O (n) so that these letters are sorted in ascending order.
Note: uppercase and lowercase letters are the same.
Example: R, B, B, B, W, W, B, R, B, w
Sorted by: B, B, R, R, w, W, W
1) describe the concept (2 points)
2) Use your familiar programming language for coding (8 points)
Java edition:
Import java. util. arrayList; import java. util. collection; import java. util. collections; import java. util. vector; public class MyDemo {public static void main (String [] args) {// TODO Auto-generated method stub System. out. println (function ("abbbdsxainiknkdkkkjjccdddcc");} public static String function (String inputString) {ArrayList <Character> arrayList = new ArrayList <> (); // Save the upper-case letter ArrayList <Character> arrayList2 = new ArrayList <> (); // Save the lower-case letter StringBuffer result = new StringBuffer (); for (int I = 0; I <inputString. length (); I ++) {if (inputString. charAt (I) <'A') {// uppercase letter arrayList. add (inputString. charAt (I);} else {arrayList2.add (inputString. charAt (I) ;}} Collections. sort (arrayList); Collections. sort (arrayList2); for (int I = 0; I <arrayList2.size (); I ++) {result. append (arrayList2.get (I);} for (int I = 0; I <arrayList. size (); I ++) {result. append (arrayList. get (I);} return result. toString ();}}
My android Learning Experience: http://jingyan.baidu.com/season/48891