Leetcode:344. Reverse String

来源:互联网 发布:外贸网站如何选择域名 编辑:程序博客网 时间:2024/05/19 16:33

题目描述:
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

我的AC代码:

public class Solution {    public String reverseString(String s) {        char[] a=s.toCharArray();        char[] temp=new char[a.length];        int j=0;        for(int i=a.length-1;i>=0;i--){            temp[j]=a[i];            j++;        }        return String.valueOf(temp);    }}
0 0
原创粉丝点击