Simple java 3ms solution


  • 0
    K
    public List<String> readBinaryWatch(int num) {
        List<String> lst = new ArrayList<String>();
        for(int i=0;i<=11;++i){
        	int hcount = (i&1) + ((i&2)>>1) + ((i&4)>>2) + ((i&8)>>3) ;
        	for(int j=0;j<=59;++j){
        		int mcount=(j&1)+((j&2)>>1)+((j&4)>>2)+((j&8)>>3)+((j&16)>>4)+((j&32)>>5);
        		if((hcount+mcount)==num){
        			String min= j<=9?"0"+j:""+j;
        			lst.add(i+":"+min);
        		}
        	}
        }
        return lst;    
    }

Log in to reply
 

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