问题:
对二维数组进行回形(蛇形)打印
代码:
package com.ziling.mianshi;
/**
* @Author: yipeng
* @Date: 2021/7/27 17:43
*/
public class ArrayBackPrint {
public static void arrayBackPrint(int[][] nums) {
if (nums == null) {
throw new RuntimeException("invalid param");
}
if (nums.length == 0) {
return;
}
int top = 0;
int bottom = nums.length - 1;
int left =0;
int right = nums[0].length - 1;
while (top <= bottom && left <= right) {
for (int i = left; i <= right; i++) {
System.out.print(nums[top][i] + " ");
}
top++;
if (top > bottom || left > right) {
break;
}
for (int i = top; i <= bottom; i&