https://leetcode.com/problems/binary-watch/

// 参考 https://discuss.leetcode.com/topic/59374/simple-python-java
// 非常棒的方法

public class Solution {
    public List<String> readBinaryWatch(int num) {
        List<String> lt = new ArrayList<String>();
        for (int m=0; m<12; m++) {
            for (int n=0; n<60; n++) {
                if (Integer.bitCount(m*64+n) == num) {
                    lt.add(String.format("%d:%02d", m, n));
                }
            }
        }
        return lt;
    }
}

 

相关文章:

  • 2021-08-17
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-01-09
  • 2021-07-23
  • 2021-12-26
  • 2021-12-29
  • 2021-06-30
  • 2022-12-23
相关资源
相似解决方案