leetcode 344: Reverse String (c#版)

来源:互联网 发布:vb财务管理系统源码 编辑:程序博客网 时间:2024/06/14 12: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) {        List<char> charlist=new List<char>();        Char[] chararray=s.ToCharArray();        for(int i=0;i<chararray.Length;i++)        {            charlist.Add(chararray[i]);        }        charlist.Reverse();        string res=string.Join("",charlist);        return res;    }}
时间是180ms,实际上这个效率很低。但是由于提交太少,没法看到自己效率的排名。时间复杂度那块还需要学习下。

0 0
原创粉丝点击