题解 | #反转字符串#
反转字符串
http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3
题目比较简单
class Solution {
public:
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
string solve(string str) {
// write code here
int i = str.length() - 1;
int j = 0;
while(i>j) swap(str[i--], str[j++]);
return str;
}
};
查看1道真题和解析