leetcode note--leetcode 344 Reverse String

来源:互联网 发布:淘宝兔八哥aj 编辑:程序博客网 时间:2024/05/17 09:08

344. Reverse String

 

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

Example:
Given s = "hello", return "olleh".

Subscribe to see which companies asked this question

public class Solution {    public String reverseString(String s) {        //回归2016-12-2        int len = s.length();        int start = 0;        int end = len-1;        char[] str = s.toCharArray();        while(start<end){            char tem = str[end];            str[end] = str[start];            str[start] = tem;            start++;            end--;        }        return new String(str);    }}

0 0