[LeetCode]344. Reverse String

来源:互联网 发布:网络在线测速 编辑:程序博客网 时间:2024/04/30 18:34

Write a function that takes a string as input and returns the string reversed.
写一个函数反转字符串
Example:
Given s = “hello”, return “olleh”.

class Solution {public:    string reverseString(string s) {        string result = "";        for(int i = s.size() - 1;i>=0;i--)            result = result + s[i];        return result;    }};
0 0
原创粉丝点击