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,实际上这个效率很低。但是由于提交太少,没法看到自己效率的排名。时间复杂度那块还需要学习下。