185
来源:互联网 发布:我想在淘宝上卖东西该怎么办 编辑:程序博客网 时间:2024/06/03 18:59
4.13
这道题简直要写懵逼了啊。
要搞清楚运动方向。
public class Solution { /** * @param matrix: a matrix of integers * @return: an array of integers */ public static int[] printZMatrix(int[][] matrix) { if(matrix == null){ return null;// write your code here } int n = matrix.length; if(n == 1){ return matrix[0]; } int m = matrix[0].length; int num = m*n; boolean[][] flag = new boolean[n][m]; int[] res = new int[ num ]; if( m == 1){ for(int k = 0;k < n; k++){ res[k] = matrix[k][0]; } return res; } res[0] = matrix[0][0]; res[1] = matrix[0][1]; int i = 0; int j = 1; int count = 1; while(count < num){ //向斜下方运动 while( i < n-1 && j > 0 && count < num-1){ res[++count] = matrix[++i][--j]; if(i == n-1 && j== m-1){ res[ ++count] = matrix[i][j]; return res; } } //向右运动 if(i == n-1 && j < m-1){ res[ ++count] = matrix[i][++j]; } // 向下运动 if( j == 0 && i < n-1){ res[++count] = matrix[++i][j]; } //向斜上方运动 while(i > 0 && j < m-1 && count < num-1){ res[++count] = matrix[--i][++j]; } //向下移动 if(j == m-1 && i < n-1){ res[++count] = matrix[++i][j]; } if(j == m-1 && i == n-1){ res[count++] = matrix[i][j]; return res; } //向右移动 if(i == 0 && j < m-1){ res[++count] = matrix[i][++j]; } } return res; }}
0 0
- 185
- 185
- rqnoj-185
- 185div2
- uva 185
- 185@365
- ocp-185
- 作文185题思路
- reactos操作系统实现(185)
- sgu 185 Two shortest
- Codeforces 185A Plant
- SGU 185 Two shortest
- Codeforces Round #185(div2)
- 185div1D题
- cf 185div2 A
- UVA 185(暴力DFS)
- codeforces 185A Plant
- uva 185 Roman Numerals
- JSP (java server page) servlet生命周期
- Win10 将开启“游戏模式”
- 删数问题
- win7 装固态升级win10 心得
- JS性能优化之创建文档碎片(document.createDocumentFragment)
- 185
- PHP性能测试工具xhprof的安装和使用
- 关于 排序 两三事
- Java 中的Synchronized解析
- enum
- 广义表 头尾表示法表示
- 线性代数,机器学习,笔记!!!
- 东风尕玩儿
- jdbcType与javaType的对应关系