binary-watch

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;
    }
}

 

posted @ 2016-09-21 01:49  blcblc  阅读(176)  评论(0编辑  收藏  举报