Skip to content

Commit 9d1e97c

Browse files
committed
Add solution #1380
1 parent 18a93dd commit 9d1e97c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
1351|[Count Negative Numbers in a Sorted Matrix](./1351-count-negative-numbers-in-a-sorted-matrix.js)|Easy|
143143
1356|[Sort Integers by The Number of 1 Bits](./1356-sort-integers-by-the-number-of-1-bits.js)|Easy|
144144
1360|[Number of Days Between Two Dates](./1360-number-of-days-between-two-dates.js)|Easy|
145+
1380|[Lucky Numbers in a Matrix](./1380-lucky-numbers-in-a-matrix.js)|Easy|
145146
1472|[Design Browser History](./1472-design-browser-history.js)|Medium|
146147
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
147148
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 1380. Lucky Numbers in a Matrix
3+
* https://leetcode.com/problems/lucky-numbers-in-a-matrix/
4+
* Difficulty: Easy
5+
*
6+
* Given an m x n matrix of distinct numbers, return all lucky numbers
7+
* in the matrix in any order.
8+
*
9+
* A lucky number is an element of the matrix such that it is the minimum
10+
* element in its row and maximum in its column.
11+
*/
12+
13+
/**
14+
* @param {number[][]} matrix
15+
* @return {number[]}
16+
*/
17+
var luckyNumbers = function(matrix) {
18+
const min = matrix.map(row => Math.min(...row));
19+
const max = matrix[0].map((_, i) => Math.max(...matrix.map(row => row[i])));
20+
21+
return min.filter(value => max.includes(value));
22+
};

0 commit comments

Comments
 (0)