Skip to content

Commit 41b2ce6

Browse files
add 2596
1 parent 3d1e7c0 commit 41b2ce6

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2596 |[Check Knight Tour Configuration](https://leetcode.com/problems/check-knight-tour-configuration/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2596.java) | | Medium |
1112
| 2595 |[Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2595.java) | | Easy |
1213
| 2586 |[Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2586.java) | | Easy |
1314
| 2583 |[Kth Largest Sum in a Binary Tree](https://leetcode.com/problems/kth-largest-sum-in-a-binary-tree/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2583.java) | | Medium |
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _2596 {
4+
public static class Solution1 {
5+
public boolean checkValidGrid(int[][] grid) {
6+
int n = grid.length;
7+
int[][] offsets = new int[][]{
8+
{-2, 1},
9+
{-1, 2},
10+
{1, 2},
11+
{2, 1},
12+
{2, -1},
13+
{1, -2},
14+
{-1, -2},
15+
{-2, -1}
16+
};
17+
int x = 0;
18+
int y = 0;
19+
int currentVal = 0;
20+
while (currentVal != n * n - 1) {
21+
boolean foundNext = false;
22+
for (int[] offset : offsets) {
23+
int newX = x + offset[0];
24+
int newY = y + offset[1];
25+
if (newX >= 0 && newX < n && newY >= 0 && newY < n && grid[newX][newY] == currentVal + 1) {
26+
currentVal++;
27+
x = newX;
28+
y = newY;
29+
foundNext = true;
30+
break;
31+
}
32+
}
33+
if (!foundNext) {
34+
return false;
35+
}
36+
}
37+
return true;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy