---
# System prepended metadata

title: 2022. Convert 1D Array Into 2D Array
tags: [Leetcode, Easy]

---

# 2022. Convert 1D Array Into 2D Array
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/convert-1d-array-into-2d-array/description/
## Code
```python=
class Solution:
    def construct2DArray(self, original: List[int], m: int, n: int) -> List[List[int]]:
        ans = []
        if m*n!=len(original): return ans
        for i in range(0, len(original), n):
            ans.append(original[i:i+n])
        return ans
```
```java=
class Solution {
    public int[][] construct2DArray(int[] original, int m, int n) {
        if(original.length!=m*n) return new int[0][0];
        int[][] ans = new int[m][n];
        for(int i=0; i<original.length; i++){
            ans[i/n][i%n] = original[i];
        }
        return ans;
    }
}
```