一、题目
二、代码
class Solution
{
public void reverseString(char[] s)
{
int left = 0 ;
int right = s.length-1;
char temp;
while(left<right)
{
temp = s[left];
s[left] = s[right];
s[right] = temp;
left++;
right--;
}
}
}
三、运行结果
四、二刷
class Solution
{
public void reverseString(char[] s)
{
int length = s.length;
// System.out.println( length );
char temp_char;
int i;
int left = 0;
int right = length-1;
for(i=0;i<length/2;i++)
{
temp_char = s[i];
s[i] = s[length-1-i];
s[length-1-i] = temp_char;
}
}
}