Skip to content

Commit 088ebc7

Browse files
add 519
1 parent 99c9038 commit 088ebc7

File tree

3 files changed

+58
-0
lines changed
  • paginated_contents/algorithms/1st_thousand
  • src
    • main/java/com/fishercoder/solutions/firstthousand
    • test/java/com/fishercoder/firstthousand

3 files changed

+58
-0
lines changed

paginated_contents/algorithms/1st_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@
319319
| 522 | [Longest Uncommon Subsequence II](https://leetcode.com/problems/longest-uncommon-subsequence-ii/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_522.java) | | Medium |
320320
| 521 | [Longest Uncommon Subsequence I](https://leetcode.com/problems/longest-uncommon-subsequence-i/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_521.java) | | Easy |
321321
| 520 | [Detect Capital](https://leetcode.com/problems/detect-capital/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_520.java) | | Easy |
322+
| 519 | [Random Flip Matrix](https://leetcode.com/problems/random-flip-matrix/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_519.java) | | Medium |HashTable, Math, Randomized, Reservoir Sampling
322323
| 518 | [Coin Change 2](https://leetcode.com/problems/coin-change-2/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_518.java) | | Medium | Array, DP
323324
| 517 | [Super Washing Machines](https://leetcode.com/problems/super-washing-machines/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_517.java) | | Hard | DP
324325
| 516 | [Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) | [Solution](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/firstthousand/_516.java) | | Medium | DP
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fishercoder.solutions.firstthousand;
2+
3+
import java.util.HashSet;
4+
import java.util.Random;
5+
import java.util.Set;
6+
7+
public class _519 {
8+
public static class Solution {
9+
10+
private int m;
11+
private int n;
12+
private Set<Integer> flipped;
13+
private Random random;
14+
15+
public Solution(int m, int n) {
16+
this.m = m;
17+
this.n = n;
18+
this.random = new Random();
19+
this.flipped = new HashSet<>();
20+
}
21+
22+
public int[] flip() {
23+
int i = random.nextInt(m);
24+
int j = random.nextInt(n);
25+
while (!flipped.add(i * n + j)) {
26+
i = random.nextInt(m);
27+
j = random.nextInt(n);
28+
}
29+
return new int[]{i, j};
30+
}
31+
32+
public void reset() {
33+
this.flipped = new HashSet<>();
34+
}
35+
}
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.firstthousand;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions.firstthousand._519;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class _519Test {
8+
9+
private static _519.Solution solution1;
10+
11+
@Test
12+
public void test1() {
13+
solution1 = new _519.Solution(3, 1);
14+
CommonUtils.printArray(solution1.flip());
15+
CommonUtils.printArray(solution1.flip());
16+
CommonUtils.printArray(solution1.flip());
17+
solution1.reset();
18+
CommonUtils.printArray(solution1.flip());
19+
}
20+
21+
}

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