|
4 | 4 | importjava.util.List;
|
5 | 5 |
|
6 | 6 | /**
|
| 7 | + * 401. Binary Watch |
| 8 | + * |
7 | 9 | * A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).
|
8 |
| -
|
9 |
| - Each LED represents a zero or one, with the least significant bit on the right. |
10 |
| -
|
| 10 | + * Each LED represents a zero or one, with the least significant bit on the right. |
11 | 11 |
|
12 | 12 | For example, the above binary watch reads "3:25".
|
13 | 13 |
|
|
24 | 24 | */
|
25 | 25 | publicclass_401 {
|
26 | 26 |
|
27 |
| -publicList<String>readBinaryWatch(intnum) { |
28 |
| -List<String>times =newArrayList<>(); |
29 |
| -for (inth =0;h <12;h++) { |
30 |
| -for (intm =0;m <60;m++) { |
31 |
| -if (Integer.bitCount(h *60 +m) ==num) { |
32 |
| -times.add(String.format("%d:%02d",h,m));//%02 means to pad this two-digit decimal number on the left with zeroes |
| 27 | +publicstaticclassSolution1 { |
| 28 | +publicList<String>readBinaryWatch(intnum) { |
| 29 | +List<String>times =newArrayList<>(); |
| 30 | +for (inth =0;h <12;h++) { |
| 31 | +for (intm =0;m <60;m++) { |
| 32 | +if (Integer.bitCount(h *60 +m) ==num) { |
| 33 | +times.add(String.format("%d:%02d",h, |
| 34 | +m));//%02 means to pad this two-digit decimal number on the left with zeroes |
| 35 | + } |
33 | 36 | }
|
34 | 37 | }
|
| 38 | +returntimes; |
35 | 39 | }
|
36 |
| -returntimes; |
37 | 40 | }
|
38 |
| - |
39 | 41 | }
|