Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9d8fe14

Browse files
committed
update 1030.matrix-cells-in-distance-order.java
1 parent 8fff439 commit 9d8fe14

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎1030.matrix-cells-in-distance-order.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public int[][] allCellsDistOrder(int R, int C, int r0, int c0) {
8282
ans[0][1] = c0;
8383

8484
for(int d=1; d<R+C; d++)
85-
for(int i=0; i<R; i++)
86-
for(int j=0; j<C; j++)
85+
for(int i=Math.max(r0-d, 0); i<Math.min(r0+d+1, R); i++)
86+
for(int j=Math.max(c0-d, 0); j<Math.min(c0+d+1, C); j++)
8787
if(Math.abs(i-r0) + Math.abs(j-c0) == d){
8888
ans[k][0] = i;
8989
ans[k][1] = j;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /