-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Junyan
committed
Jul 7, 2020
1 parent
4d85261
commit 80be51e
Showing
2 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/org/zjy/learn/code/google/MatrixWiredIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.zjy.learn.code.google; | ||
|
||
import org.zjy.learn.util.Application; | ||
|
||
@Application(time = "06/04/2020 13:15") | ||
public class MatrixWiredIterator implements Runnable { | ||
@Override | ||
public void run() { | ||
int[][] matrix = new int[][]{ | ||
{1,2,3,4}, | ||
{5,1,2,3}, | ||
{6,5,1,2}, | ||
{7,6,5,1}, | ||
}; | ||
matrixIterator(matrix); | ||
} | ||
// 矩阵斜着遍历 | ||
private void matrixIterator(int[][] matrix) { | ||
int n = matrix[0].length; | ||
int m = matrix.length; | ||
for (int d = 1; d < n; d++) { | ||
for (int l = 0; l < m - d; l++) { | ||
int r = l + d; | ||
System.out.println(matrix[l][r]); | ||
} | ||
} | ||
// for (int d = 1; d < n; d++) { | ||
// for (int r = m - d; r > 0; r--) { | ||
// int l = r - d + 1; | ||
// System.out.println(matrix[l][r]); | ||
// } | ||
// } | ||
} | ||
} |