File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * 401. Binary Watch
3+ * https://leetcode.com/problems/binary-watch/
4+ * Difficulty: Easy
5+ *
6+ * A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom
7+ * to represent the minutes (0-59). Each LED represents a zero or one, with the least significant
8+ * bit on the right.
9+ * - For example, the below binary watch reads "4:51".
10+ * Given an integer turnedOn which represents the number of LEDs that are currently on (ignoring
11+ * the PM), return all possible times the watch could represent. You may return the answer in
12+ * any order.
13+ * The hour must not contain a leading zero.
14+ * - For example, "01:00" is not valid. It should be "1:00".
15+ * The minute must consist of two digits and may contain a leading zero.
16+ * - For example, "10:2" is not valid. It should be "10:02".
17+ */
18+
19+ /**
20+ * @param {number } turnedOn
21+ * @return {string[] }
22+ */
23+ var readBinaryWatch = function ( turnedOn ) {
24+ const result = [ ] ;
25+
26+ for ( let h = 0 ; h < 12 ; h ++ ) {
27+ for ( let m = 0 ; m < 60 ; m ++ ) {
28+ if ( h . toString ( 2 ) . split ( '1' ) . length - 1 + m . toString ( 2 ) . split ( '1' ) . length - 1 === turnedOn ) {
29+ result . push ( `${ h } :${ m < 10 ? '0' + m : m } ` ) ;
30+ }
31+ }
32+ }
33+
34+ return result ;
35+ } ;
Original file line number Diff line number Diff line change 319319398|[ Random Pick Index] ( ./0398-random-pick-index.js ) |Medium|
320320399|[ Evaluate Division] ( ./0399-evaluate-division.js ) |Medium|
321321400|[ Nth Digit] ( ./0400-nth-digit.js ) |Medium|
322+ 401|[ Binary Watch] ( ./0401-binary-watch.js ) |Easy|
322323404|[ Sum of Left Leaves] ( ./0404-sum-of-left-leaves.js ) |Easy|
323324405|[ Convert a Number to Hexadecimal] ( ./0405-convert-a-number-to-hexadecimal.js ) |Easy|
324325407|[ Trapping Rain Water II] ( ./0407-trapping-rain-water-ii.js ) |Hard|
You can’t perform that action at this time.
0 commit comments