leetcode401 二进制手表问题

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

class Solution {
    public List<String> readBinaryWatch(int turnedOn) {
        List<String> result = new ArrayList<String>();
        for(int counthour = 0; counthour < 12; counthour++) {
            for(int countminute = 0; countminute < 60; countminute++) {
                if(Integer.bitCount(counthour) + Integer.bitCount(countminute) == turnedOn){
                    result.add(counthour + ":" + (countminute>=10 ? "" : "0" ) + countminute);
                }
            }
        }
        return result;
    }
}

  

posted @ 2021-09-17 15:38  leagueandlegends  阅读(15)  评论(0编辑  收藏  举报