Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1762b78

Browse files
committed
Add solution #1424
1 parent f707631 commit 1762b78

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,297 LeetCode solutions in JavaScript
1+
# 1,298 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1089,6 +1089,7 @@
10891089
1420|[Build Array Where You Can Find The Maximum Exactly K Comparisons](./solutions/1420-build-array-where-you-can-find-the-maximum-exactly-k-comparisons.js)|Hard|
10901090
1422|[Maximum Score After Splitting a String](./solutions/1422-maximum-score-after-splitting-a-string.js)|Easy|
10911091
1423|[Maximum Points You Can Obtain from Cards](./solutions/1423-maximum-points-you-can-obtain-from-cards.js)|Medium|
1092+
1424|[Diagonal Traverse II](./solutions/1424-diagonal-traverse-ii.js)|Medium|
10921093
1431|[Kids With the Greatest Number of Candies](./solutions/1431-kids-with-the-greatest-number-of-candies.js)|Easy|
10931094
1436|[Destination City](./solutions/1436-destination-city.js)|Easy|
10941095
1437|[Check If All 1's Are at Least Length K Places Away](./solutions/1437-check-if-all-1s-are-at-least-length-k-places-away.js)|Easy|
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* 1424. Diagonal Traverse II
3+
* https://leetcode.com/problems/diagonal-traverse-ii/
4+
* Difficulty: Medium
5+
*
6+
* Given a 2D integer array nums, return all elements of nums in diagonal order as shown
7+
* in the below images.
8+
*/
9+
10+
/**
11+
* @param {number[][]} nums
12+
* @return {number[]}
13+
*/
14+
var findDiagonalOrder = function(nums) {
15+
const diagonalGroups = [];
16+
17+
for (let row = 0; row < nums.length; row++) {
18+
for (let col = 0; col < nums[row].length; col++) {
19+
const sum = row + col;
20+
if (!diagonalGroups[sum]) {
21+
diagonalGroups[sum] = [];
22+
}
23+
diagonalGroups[sum].push(nums[row][col]);
24+
}
25+
}
26+
27+
const result = [];
28+
for (const group of diagonalGroups) {
29+
if (group) {
30+
result.push(...group.reverse());
31+
}
32+
}
33+
34+
return result;
35+
};

0 commit comments

Comments
 (0)