leetcode——344——Reverse String

来源:互联网 发布:dota2和lol区别知乎 编辑:程序博客网 时间:2024/06/06 11:44

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) {        int  n= s.size();        if(n<=1)            return s;       string res = "";           for(int i = 0;i<n;i++)       {           res=s[i]+res;       }       return res;    }     };

0 0