Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit088ebc7

Browse files
add 519
1 parent99c9038 commit088ebc7

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+
packagecom.fishercoder.solutions.firstthousand;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Random;
5+
importjava.util.Set;
6+
7+
publicclass_519 {
8+
publicstaticclassSolution {
9+
10+
privateintm;
11+
privateintn;
12+
privateSet<Integer>flipped;
13+
privateRandomrandom;
14+
15+
publicSolution(intm,intn) {
16+
this.m =m;
17+
this.n =n;
18+
this.random =newRandom();
19+
this.flipped =newHashSet<>();
20+
}
21+
22+
publicint[]flip() {
23+
inti =random.nextInt(m);
24+
intj =random.nextInt(n);
25+
while (!flipped.add(i *n +j)) {
26+
i =random.nextInt(m);
27+
j =random.nextInt(n);
28+
}
29+
returnnewint[]{i,j};
30+
}
31+
32+
publicvoidreset() {
33+
this.flipped =newHashSet<>();
34+
}
35+
}
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
packagecom.fishercoder.firstthousand;
2+
3+
importcom.fishercoder.common.utils.CommonUtils;
4+
importcom.fishercoder.solutions.firstthousand._519;
5+
importorg.junit.jupiter.api.Test;
6+
7+
publicclass_519Test {
8+
9+
privatestatic_519.Solutionsolution1;
10+
11+
@Test
12+
publicvoidtest1() {
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)

[8]ページ先頭

©2009-2025 Movatter.jp