美文网首页
519. 随机翻转矩阵

519. 随机翻转矩阵

作者: 漫行者_ | 来源:发表于2021-11-27 23:50 被阅读0次

    519. 随机翻转矩阵

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

    class Solution {
        int count = 0;
        int _m = 0;
        int _n = 0;
        Random r = new Random();
        Map<Integer, Integer> 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. 随机翻转矩阵

          本文链接:https://www.haomeiwen.com/subject/ulhcxrtx.html