#Leetcode# 344. Reverse String

https://leetcode.com/problems/reverse-string/

 

Write a function that takes a string as input and returns the string reversed.

Example 1:

Input: "hello"
Output: "olleh"

Example 2:

Input: "A man, a plan, a canal: Panama"
Output: "amanaP :lanac a ,nalp a ,nam A"

代码:

class Solution {
public:
    string reverseString(string s) {
        int len = s.length();
        for(int i = 0; i < len / 2; i ++)
            swap(s[i], s[len - i - 1]);
        return s;
    }
};

  

posted @ 2018-11-20 22:30  丧心病狂工科女  阅读(79)  评论(0编辑  收藏  举报