-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.java
More file actions
34 lines (34 loc) · 951 Bytes
/
day5.java
File metadata and controls
34 lines (34 loc) · 951 Bytes
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
//LEETCODE POTD
//problem 1:https://leetcode.com/problems/find-missing-and-repeated-values/?envType=daily-question&envId=2025-03-06
class Solution {
public int[] findMissingAndRepeatedValues(int[][] grid) {
HashSet <Integer> set=new HashSet <>();
int arr[]=new int[2];
int i,j;
for(i=0;i<grid.length;i++){
for(j=0;j<grid[0].length;j++){
if(set.contains(grid[i][j])){
arr[0]=grid[i][j];
}
else{
set.add(grid[i][j]);
}
}
}
int k=1;
for(i=0;i<grid.length;i++){
for(j=0;j<grid[0].length;j++){
if(set.contains(k++)){
continue;
}
else{
arr[1]=--k;
break;
}
}
}
return arr;
}
}
//TC:O(n*m)
//SC:O(n*m)