Leetcode no. 344

来源:互联网 发布:高分少女 知乎: 编辑:程序博客网 时间:2024/05/17 07:04

344. 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) {        if (s.length()==0) return s;        char[] c= s.toCharArray();        int i=0, j=c.length-1;        while (i<j){            char tmp= c[i];            c[i]=c[j];            c[j]=tmp;            i++; j--;        }        return new String(c);    }}


0 0
原创粉丝点击