-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_519.java
36 lines (30 loc) · 865 Bytes
/
_519.java
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
package com.fishercoder.solutions.firstthousand;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class _519 {
public static class Solution {
private int m;
private int n;
private Set<Integer> flipped;
private Random random;
public Solution(int m, int n) {
this.m = m;
this.n = n;
this.random = new Random();
this.flipped = new HashSet<>();
}
public int[] flip() {
int i = random.nextInt(m);
int j = random.nextInt(n);
while (!flipped.add(i * n + j)) {
i = random.nextInt(m);
j = random.nextInt(n);
}
return new int[] {i, j};
}
public void reset() {
this.flipped = new HashSet<>();
}
}
}