您的位置:首页 > 其它

leetcode submission/20160720(reverse string)

2016-07-20 15:57 267 查看
北京大雨,妈的下了一天

I choose a rather easy topic, cause' it's the first time that I code in leetcode, prior object is to test.

Topic:

Reverse String

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

Example:
Given s = "hello", return "olleh".

/************************************************************/

My
answer:

#include
<stdio.h>

#include <string>

#include <iostream>

class Solution {

public:

    string reverseString(string s) {

        for (int i = 0;i<s.length()/2;++i) {

            char c = s[i];

            s[i] = s[s.length() - i - 1];

            s[s.length() - i - 1] = c;

        }

        

        return s;

    }

};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: