344. Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
反转字符串,逼我不用 reverse
class Solution { public: string reverseString(string s) { int n = s.length(); int l = 0, r = n - 1; while(l < r) { swap(s[l++],s[r--]); } return s; } };
原文地址:http://www.cnblogs.com/pk28/
与有肝胆人共事,从无字句处读书。
欢迎关注公众号:
欢迎关注公众号: