北京大雨,妈的下了一天
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;
}
};