We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2264a14 commit b3a83ccCopy full SHA for b3a83cc
src/BinaryWatch.java
@@ -0,0 +1,39 @@
1
+import java.util.ArrayList;
2
+import java.util.List;
3
+
4
+public class BinaryWatch {
5
+ public List<String> readBinaryWatch(int num) {
6
+ List<String> result = new ArrayList<String>();
7
8
+ for(int i = 0 ; i < 12 ; i++){
9
+ for(int j=0 ; j < 60 ; j++){
10
+ int total = countDigits(i) + countDigits(j);
11
+ if(total == num){
12
+ StringBuilder time = new StringBuilder();
13
+ time.append(i)
14
+ .append(":")
15
+ .append(j < 10 ? 0 : "")
16
+ .append(j);
17
18
+ result.add(time.toString());
19
+ }
20
21
22
23
+ return result;
24
25
26
+ public int countDigits(int num){
27
+ int result = 0;
28
29
+ while(num > 0){
30
+ if((num & 1) == 1){
31
+ result++;
32
33
34
+ num >>= 1;
35
36
37
38
39
+}
0 commit comments