字符串去掉空格,空间复杂度o(1),时间复杂度o(n),
输入"ab c d",输出“abcd”
public static char[] gridBlank(String s) {
char [] chars = s.toCharArray();
if(chars.length==0||chars==null)
return null;
int left = 0;
for(int right= 0;right < chars.length;right++)
{
while(chars[right] == ' ')
{
right++;
if(right==chars.length) break;
}
if(right<chars.length)
chars[left++] = chars[right];
}
return Arrays.copyOfRange(chars, 0, left+1);
}