LeetCode 344. Reverse String

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = "hello", return "olleh".

AC代码:

 string reverseString(string s)
    {
        string ans;
        int length = s.length();
        for(int i = length-1;i>=0;i--)
            ans+=s[i];
            return ans;
       // return reverse(s.begin(),s.end());
    }
有一点没理解的,为什么不让用reverse函数,本来一行代码解决的,在本地的编译器上都编译通过了( ▼-▼ )

你可能感兴趣的:(leetcode刷题)