File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 142
142
1351|[ Count Negative Numbers in a Sorted Matrix] ( ./1351-count-negative-numbers-in-a-sorted-matrix.js ) |Easy|
143
143
1356|[ Sort Integers by The Number of 1 Bits] ( ./1356-sort-integers-by-the-number-of-1-bits.js ) |Easy|
144
144
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|
145
146
1472|[ Design Browser History] ( ./1472-design-browser-history.js ) |Medium|
146
147
1598|[ Crawler Log Folder] ( ./1598-crawler-log-folder.js ) |Easy|
147
148
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments