Java - new solution using streams
\nclass Solution {\n    public int[][] matrixReshape(int[][] nums, int r, int c) {\n        int n = nums.length;\n        int m = nums[0].length;\n        if(r*
```\nclass Solution {\n    public int[][] matrixReshape(int[][] nums, int r, int c) {\n        int n = nums.length;\n        int m = nums[0].length;\n        if(r*c != n*m || r == n) return nums;\n        int[][] res = new int[r][c];\n        \n\t\tAtomicInteger ai = new AtomicInteger();\n\t\tArrays.stream(nums)\n\t\t\t\t.flatMapToInt(Arrays::stream)\n\t\t\t\t.forEach(x -> res[ ai.get() / c ][ ai.getAndIncrement() % c ] = x);\n        return res;\n    }\n}\n```
['Java']