1. 程式人生 > >螺旋打印2D數組

螺旋打印2D數組

void 思考 pri length clas sta off pre 打印

//一破題付出血的代價   多思考!
public
static void offer(int [][]a){ int left=0,right=a.length-1,low=0,high=a[0].length-1; while(low<=high){ for(int i=left;i<=right;i++){//123 System.out.print(a[left][i]+" "); } low++; for(int i=low;i<=high;i++){//
69 System.out.print(a[i][right]+" "); } right--; for(int i=right;i>=left;i--){//87 System.out.print(a[high][i]+" "); } high--; for(int i=high;i>=low;i--){//45 System.out.print(a[i][left]+"
"); } left++; } }

螺旋打印2D數組