Skip to content

Commit

Permalink
Added 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
MonitSharma authored Sep 1, 2024
1 parent 97d98d8 commit 6330e57
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 2022-converting-1d-to-2d/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
vector<vector<int>> construct2DArray(vector<int>& original, int m, int n) {
if (original.size() != m * n)
return {};

vector<vector<int>> ans(m, vector<int>(n));

for (int i = 0; i < original.size(); ++i)
ans[i / n][i % n] = original[i];

return ans;
}
};
13 changes: 13 additions & 0 deletions 2022-converting-1d-to-2d/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public int[][] construct2DArray(int[] original, int m, int n) {
if (original.length != m * n)
return new int[][] {};

int[][] ans = new int[m][n];

for (int i = 0; i < original.length; ++i)
ans[i / n][i % n] = original[i];

return ans;
}
}
12 changes: 12 additions & 0 deletions 2022-converting-1d-to-2d/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def construct2DArray(self, original: list[int],
m: int, n: int) -> list[list[int]]:
if len(original) != m * n:
return []

ans = [[0] * n for _ in range(m)]

for i, num in enumerate(original):
ans[i // n][i % n] = num

return ans
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ This repository contains solutions to over 500 Leetcode problems that are organi
| 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) |
| 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) |
| 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) |
| 2022 | Convert 1D Array Into 2D Array | [![Medium](https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white)]() |
| 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) |
| 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) |
| 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) |
Expand Down

0 comments on commit 6330e57

Please sign in to comment.