-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
88 lines (87 loc) · 2.25 KB
/
Copy pathsolution.java
File metadata and controls
88 lines (87 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 36. Valid Sudoku
// https://leetcode.com/problems/valid-sudoku/
// Medium | Java | Accepted 2024-09-06
// Runtime 74 ms | Memory 45.2 MB
class Solution {
public boolean isValidSudoku(char[][] board) {
Map<Character, Integer> map = new HashMap<>();
for(int i = 0; i < board.length; i++)
{
for(int j = 0; j<board[0].length; j++)
{
System.out.print(board[i][j] + " ");
if(!map.containsKey(board[i][j]))
{
map.put(board[i][j], 1);
}
else
{
if(board[i][j]!='.')
{
return false;
}
}
}
System.out.println();
map.clear();
}
for(int k = 0; k < board.length; k++)
{
for(int l = 0; l<board[0].length; l++)
{
if(!map.containsKey(board[l][k]))
{
map.put(board[l][k], 1);
}
else
{
if(board[l][k]!='.')
{
return false;
}
}
}
map.clear();
}
int count = 0;
for(int m = 0; m < board.length; m++)
{
if(count>=3)
{
break;
}
m = 0;
map.clear();
for(int n = count*3; n<board[0].length; n++)
{
if(!map.containsKey(board[m][n]))
{
map.put(board[m][n], 1);
}
else
{
if(board[m][n]!='.')
{
return false;
}
}
if((n+1)%3==0&&n!=0)
{
m++;
n-=3;
if(m%3==0)
{
map.clear();
}
}
if(m==9)
{
break;
}
}
m = 0;
count++;
}
return true;
}
}