344. Reverse String 反转字符串

来源:互联网 发布:超图软件股票最新消息 编辑:程序博客网 时间:2024/06/07 19:14

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==""||s==null) {return s;}       char [] str = s.toCharArray();       char [] strstr = new char[str.length];       String string = "";       for(int i = str.length-1;i>=0;i--)       {       strstr[str.length-1-i] = str[i];       }       return new String(strstr);}}


时间复杂度:o(n)

空间复杂度:o(n)


0 0
原创粉丝点击