Skip to content

Commit 6330e57

Browse files
authored
Added 2022
1 parent 97d98d8 commit 6330e57

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

2022-converting-1d-to-2d/solution.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
4+
if (original.size() != m * n)
5+
return {};
6+
7+
vector<vector<int>> ans(m, vector<int>(n));
8+
9+
for (int i = 0; i < original.size(); ++i)
10+
ans[i / n][i % n] = original[i];
11+
12+
return ans;
13+
}
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int[][] construct2DArray(int[] original, int m, int n) {
3+
if (original.length != m * n)
4+
return new int[][] {};
5+
6+
int[][] ans = new int[m][n];
7+
8+
for (int i = 0; i < original.length; ++i)
9+
ans[i / n][i % n] = original[i];
10+
11+
return ans;
12+
}
13+
}

2022-converting-1d-to-2d/solution.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def construct2DArray(self, original: list[int],
3+
m: int, n: int) -> list[list[int]]:
4+
if len(original) != m * n:
5+
return []
6+
7+
ans = [[0] * n for _ in range(m)]
8+
9+
for i, num in enumerate(original):
10+
ans[i // n][i % n] = num
11+
12+
return ans

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ This repository contains solutions to over 500 Leetcode problems that are organi
184184
| 1964 | Find the Longest Valid Obstacle Course at Each Position | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-1964-find-the-longest-valid-obstacle-course-at-each-position-ade63a37c125) |
185185
| 1970 | Last Day Where You Can Still Cross | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-1970-last-day-where-you-can-still-cross-694827e6055) |
186186
| 2009 | Minimum Number of Operations to Make Array Continuous | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-2009-minimum-number-of-operations-to-make-array-continuous-334e1e25f826) |
187+
| 2022 | Convert 1D Array Into 2D Array | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)]() |
187188
| 2024 | Maximize the confusion of an Exam | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-problem-2024-maximize-the-confusion-of-an-exam-1754351c0c60) |
188189
| 2038 | Remove Colored Pieces if Both Neighbors are the same color | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-2038-remove-colored-pieces-if-both-neighbors-are-the-same-color-aec52bf4300d) |
189190
| 2050 | Parallel Courses III | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)](https://medium.com/@_monitsharma/daily-leetcode-problems-2050-parallel-courses-iii-87d84ef83437) |

0 commit comments

Comments
 (0)