这是我几天前去公司的笔试题目,当时想的不太清楚,所以没具体写出来,只是用语言描述了一下,下面我将贴出我的方法,如果大家有什么更好的方法别忘记分享出来哦;
public static void main(String[] args) {
/**/
String str="wwiiiwwiinnn";
String[] strs = str.split("");
int a=0,b=0,c=0;
int temp=0;
for(String st:strs){
if(st.equals("w")){
a++;
}
if(st.equals("i")){
b++;
}
if(st.equals("n")){
c++;
}
temp=a > b ? (a > c ? a : c) : b > c ? b : c;
}
for(int i=0;i<temp;i++){
if(a>0){
System.out.print("w");
a--;
}
if(b>0){
System.out.print("i");
b--;
}
if(c>0){
System.out.print("n");
c--;
}
}
}