Skip to content

Commit 3b2d8ee

Browse files
committed
Runtime: 45 ms (Top 62.26%) | Memory: 50.7 MB (Top 63.21%)
1 parent 3dbd3cb commit 3b2d8ee

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/algorithms/R/Random Flip Matrix/Random Flip Matrix.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 45 ms (Top 62.26%) | Memory: 50.7 MB (Top 63.21%)
12
// Swap Tail Element Solution
23
// 1. Get a random number between [0, size-1]
34
// 2. size - 1
@@ -10,7 +11,7 @@ class Solution {
1011
private int size;
1112
private Random random;
1213
private Map<Integer, Integer> map;
13-
14+
1415
public Solution(int m, int n) {
1516
M = m;
1617
N = n;
@@ -19,7 +20,7 @@ public Solution(int m, int n) {
1920
random = new Random();
2021
map = new HashMap<>();
2122
}
22-
23+
2324
public int[] flip() {
2425
if (size <= 0) return new int[]{-1, -1}; // or throw exception.
2526
Integer rand = random.nextInt(size);
@@ -29,7 +30,7 @@ public int[] flip() {
2930
map.put(rand, tail);
3031
return new int[]{idx / N, idx % N};
3132
}
32-
33+
3334
public void reset() {
3435
map = new HashMap();
3536
size = CAPACITY;
@@ -41,4 +42,4 @@ public void reset() {
4142
* Solution obj = new Solution(m, n);
4243
* int[] param_1 = obj.flip();
4344
* obj.reset();
44-
*/
45+
*/

0 commit comments

Comments
 (0)