344. Reverse String

来源:互联网 发布:昆山编程培训 编辑:程序博客网 时间:2024/05/18 00:12

Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = “hello”, return “olleh”.

public class Solution {    public String reverseString(String s) {        char[] str = s.toCharArray();        int start = 0;        int end = str.length - 1;        while (start < end) {            char temp = str[start];            str[start] = str[end];            str[end] = temp;            start++;            end--;        }        return new String(str);    }}
0 0