码迷,mamicode.com
首页 > 编程语言 > 详细

leetcode344 Reverse String Java

时间:2017-02-23 13:58:42      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:array   return   ring   code   new   toc   res   ack   cte   

自己写法,不过不被leetcode接受,提示Time Limit Exceeded~~~

public String reverseString(String s) {
        String res = "";
        Stack<Character> stack = new Stack<>();
        char[] ch = s.toCharArray();
        int count = 0;
        for(char c : ch) {
            count++;
            stack.push(c);
        }
        for(int i=0; i<count;i++) {
            res += stack.pop();
        }
        return res;
    }

 

leetcode344 Reverse String Java

标签:array   return   ring   code   new   toc   res   ack   cte   

原文地址:http://www.cnblogs.com/LoveBell/p/6432839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!