题解 | #反转字符串#
反转字符串
http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3
class Solution {
public:
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
string solve(string str) {
// write code here
/*int l=0,r=str.size()-1;
while(l<r){
int temp=str[l];
str[l]=str[r];
str[r]=temp;
l++;r--;
}
return str;*/
int n=str.size();
string s(n,0);
for(int i=0;i<n;i++){
s[i]=str[n-1-i];
}
return s;
//栈
}
};
顺丰集团工作强度 406人发布