straightforward java answer


  • 35
    F
        public List<String> readBinaryWatch(int num) {
            ArrayList<String> result = new ArrayList<>();
            for (int i = 0; i < 12; i++) {
                for (int j = 0; j < 60; j++) {
                    if (Integer.bitCount(i) + Integer.bitCount(j) == num) {
                        result.add(String.format("%d:%02d", i, j));
                    }
                }
            }
            return result;
        }

  • 1
    N

    @fhqplzj said in straightforward java answer:

        public List<String> readBinaryWatch(int num) {
            ArrayList<String> result = new ArrayList<>();
            for (int i = 0; i < 12; i++) {
                for (int j = 0; j < 60; j++) {
                    if (Integer.bitCount(i) + Integer.bitCount(j) == num) {
                        result.add(String.format("%d:%02d", i, j));
                    }
                }
            }
            return result;
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.