编写一个类似 一串英文 比如说 How old are you !? I don't understand 函数实现倒序:understand don't I !? you are old How。不准使用现有的类库 如 String StringBuffer ArrayList List Map 等
public char[] funaction (char[] input){
//首先进行构造一个二维数组
int twoCharLength = 1; //为了补全空格后+1
for(int i = input.length - 1;i>= 0 ;i --){
if(input[i] == ' '){
twoCharLength++;
}
}
char[][] tempTwoChar = new char[twoCharLength][];
int index = 0;
int tepmIndex = 0;
for(int i = input.length - 1;i>= 0 ;i --){
if(input[i] == ' '){
tempTwoChar[tepmIndex++] = new char[index];
index = 0;
}else{
index ++;
}
}
tempTwoChar[tepmIndex] = new char[index];//将最后一个补全
index = 0;
int endIndex = 0;
for(int i = input.length - 1;i>= 0 ;i --){
if(input[i] != ' '){
tempTwoChar[index][endIndex++] = input[i];
}else{
endIndex = 0;
index++;
}
}
index = 0;
for(char[] counmChar:tempTwoChar){
for(int i = counmChar.length - 1; i >= 0 ; i--){
input[index++] = counmChar[i];
}
if(index < input.length){
input[index++] = ' ';
}
}
return input;
}
如有更好的思路或者更优的算法 欢迎留言探讨!风雨无阻、我在这里等你!