519. 随机翻转矩阵

519. 随机翻转矩阵

学会移动后面的数!!!!!!!!

class Solution {
    int count = 0;
    int _m = 0;
    int _n = 0;
    Random r = new Random();
    Map map = new HashMap<>();
    public Solution(int m, int n) {
        _m = m;
        _n = n;
        count = m * n;
    }

    public void reset() {
        count = _n *_m;
        map.clear();
    }
    
    public int[] flip() {
        int x = r.nextInt(count--);
        int idx = map.getOrDefault(x, x);
        map.put(x, map.getOrDefault(count, count));
        return new int[] {idx/_n, idx%_n};
    }
}

你可能感兴趣的:(519. 随机翻转矩阵)