题解 | #逆时针打印矩阵#

顺时针打印矩阵

http://www.nowcoder.com/practice/9b4c81a02cd34f76be2659fa0d54342a

import java.util.ArrayList; public class Solution { public ArrayList printMatrix(int [][] matrix) { int row = matrix.length - 1; int col = matrix[0].length - 1; System.out.println(row); System.out.println(col); int i = 0; int j = 0; ArrayList list = new ArrayList<>(); while(i <= row && j <= col){

        for(int temp = i;temp <= col;temp ++){
            list.add(matrix[i][temp]);
        }
       
        if(++ i > row) break;
        for(int temp = i;temp <= row;temp ++){
            list.add(matrix[temp][col]);
        }
       
        if(-- col < j) break;
        for(int temp = col ;temp >= j;temp --){
            list.add(matrix[row][temp]);
        }
      
        if(-- row < i)break;
        for(int temp = row ;temp >= i;temp --){
            list.add(matrix[temp][j]);
        }
      
        if(++ j > col) break;

    }
    return list;
}

}

全部评论

相关推荐

码农索隆:竞争压力小,就你一个不用卷
点赞 评论 收藏
分享
tttk_:就是人多。 有的是条件和你差不多然后没在od待过的人。 所以就拿这个筛你了。 就和卡学历一样,人太多了。 从公司角度,这样做节省精力,更方便。 没办法谁叫现在人多呢
第一份工作能做外包吗?
点赞 评论 收藏
分享
Twilight_m...:经典我朋友XXXX起手,这是那种经典的不知道目前行情搁那儿胡编乱造瞎指导的中年人,不用理这种**
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务