题解 | #反转字符串#

反转字符串

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

/**
字符串装字符数组处理,双指针交换两指针的值

 public static String solve (String str) {
        // write code here
        char[] chars = str.toCharArray();
        int l=0;
        int r=chars.length-1;
        while (l<r){
            char temp=' ';
            temp=chars[r];
            chars[r]=chars[l];
            chars[l]=temp;
            l++;r--;
        }
        return new String(chars);
    }
全部评论

相关推荐

天门一键开:她的意思是问你有没有论文吧
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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