标签:
主要是boundary的条件
public class Solution { public void rotate(int[][] matrix) { if(matrix==null || matrix.length==0 || matrix[0].length==0) return; int len = matrix.length-1; for(int i=0; i<=len;i++){ for(int j=i; j<len-i;j++){ // 注意这里j exclusive to boundary len-i int tmp = matrix[i][j]; matrix[i][j] = matrix[len-j][i]; matrix[len-j][i] = matrix[len-i][len-j]; matrix[len-i][len-j] = matrix[j][len-i]; matrix[j][len-i] = tmp; } } } }
标签:
原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4424515.html