其他分享
首页 > 其他分享> > LeetCode344. 反转字符串

LeetCode344. 反转字符串

作者:互联网

一、题目描述

二、解法

class Solution {
    public void reverseString(char[] s) {
        if (s == null || s.length == 0) return;
        int l = 0, r = s.length - 1;
        while (l < r) {
            swap(s, l, r);
            l ++;
            r --;
        }
    }
    private void swap(char[] chars, int a, int b) {
        char temp = chars[a];
        chars[a] = chars[b];
        chars[b] = temp;
    }
}

 

标签:int,反转,chars,LeetCode344,char,length,swap,字符串,void
来源: https://www.cnblogs.com/HuangYJ/p/14093636.html