题目: Write a function that takes a string as input and returns the string reversed.
Example: Given s = “hello”, return “olleh”.
思路: 逆序一个字符串,用reverse_iterator
代码:
class Solution {
public:
string reverseString(
string s) {
string s1;
for (
string::reverse_iterator ix = s.rbegin(); ix != s.rend(); ++ix){
s1 += *ix;
}
return s1;
}
};
转载请注明原文地址: https://ju.6miu.com/read-12412.html