快慢指针算法-数组反转

    public static void main(String[] args) {
        int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int startI = 0;
        int endI = a.length - 1;
        while (startI <= endI) {
            int temp = a[startI];
            a[startI] = a[endI];
            a[endI] = temp;
            startI++;
            endI--;
        }
        System.out.println(JSON.toJSONString(a));
    }

 

posted @ 2020-07-14 00:36  使用D  阅读(159)  评论(0编辑  收藏  举报