LeetCode *** 344. Reverse String

来源:互联网 发布:提供rs485数据电缆价格 编辑:程序博客网 时间:2024/04/29 12:55

题目:

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 t="";        for(int pos=s.length()-1;pos>=0;--pos)            t+=s[pos];        return t;    }};


0 0
原创粉丝点击