题解 | #反转字符串#

反转字符串

http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3

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;
    }
};
全部评论

相关推荐

11-11 16:40
已编辑
门头沟学院 人工智能
不知道怎么取名字_:这个有点不合理了,相当于已经毕业了,但还是没转正,这不就是白嫖
点赞 评论 收藏
分享
头像
10-27 15:50
门头沟学院 Java
想进开水团喝开水:有一种店 只能外卖 不能堂食 你猜为什么
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务