题解 | #反转字符串#

反转字符串

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

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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