leetcode-401. Binary Watch

401. Binary Watch

java代码:

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

  

posted @ 2017-03-29 17:39  世人谓我恋长安  阅读(144)  评论(0编辑  收藏  举报