[leetcode] 344. Reverse String

题目:

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) {
        if(s.size() == 0) return s;
        for(int i = 0; i <= (s.size()-1)/2; i++){
            char t = s[i];
            s[i] = s[s.size()-1-i];
            s[s.size()-1-i] = t;
        }
         return s;
    }
   
};

猜你喜欢

转载自blog.csdn.net/jing16337305/article/details/80325630