class Solution {
public:
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
//很容易想到用栈来反转吧,顺便说下这个代码运行时间打败百分之百的c++代码哦(得意)
//代码没啥好说的,学过栈的都能看懂吧
string solve(string str) {
// write code here
char stack[1000];
int top=-1;
for(int i=0;i<str.size();i++)
{
stack[++top]=str[i];
}
string temp;
while(top!=-1)
{
temp+=stack[top--];
}
return temp;
}
}; 
京公网安备 11010502036488号