-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path519.cpp
More file actions
33 lines (30 loc) · 702 Bytes
/
519.cpp
File metadata and controls
33 lines (30 loc) · 702 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
class Solution {
public:
int size;
int row;
int col;
unordered_map<int, int> mp;
Solution(int m, int n) {
row = m;
col = n;
size = m * n;
}
vector<int> flip() {
int index = rand() % size;
int temp = index;
size--;
if (mp.find(index) != mp.end()) index = mp[index];
mp[temp] = mp.count(size) ? mp[size] : size;
return {index / col, index % col};
}
void reset() {
mp.clear();
size = row * col;
}
};
/**
* Your Solution object will be instantiated and called as such:
* Solution* obj = new Solution(m, n);
* vector<int> param_1 = obj->flip();
* obj->reset();
*/