Utopi
a

反转字符串

So easy to solve, needless to practise

Write a function that reverses a string. The input string is given as an array of characters char[].

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

You may assume all the characters consist of printable ascii characters

Example

Input: ["h","e","l","l","o"] Output: ["o","l","l","e","h"]

我的( 1 ms )

public void reverseString(char[] s) { char tem='a'; for (int i=0;i<s.length/2;i++){ tem=s[i]; s[i]=s[s.length-i-1]; s[s.length-i-1]=tem; } }

没啥难的 ╮(╯▽╰)╭

1 ms

class Solution { public void reverseString(char[] s) { int i = 0, j = s.length -1; while (i < j) { char t = s[i]; s[i] = s[j]; s[j] = t; i++; j--; } } }