forked from haoel/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.cpp
More file actions
24 lines (22 loc) · 674 Bytes
/
ReverseString.cpp
File metadata and controls
24 lines (22 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Source : https://leetcode.com/problems/reverse-string/
// Author : Hao Chen
// Date : 2016-05-29
/***************************************************************************************
*
* 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 len = s.size();
for (int i=0; i<len/2; i++) {
char ch = s[i];
s[i] = s[len-i-1];
s[len-i-1] = ch;
}
return s;
}
};