Intuitive Javascript Solution


  • 0
    D
    var readBinaryWatch = function(num) {
        const output = [];
        
        // find the number of ones in bit expression of time and match with num
        for (let h = 0; h < 12; h++) {
            for (let m = 0; m < 60; m++) {
                const ones = Number(h * 64 + m).toString(2).split('').filter(d => d === '1').length;
                if (ones === num) output.push(m < 10 ? `${h}:0${m}` : `${h}:${m}`);
            }
        }
        
        return output;
    };
    

Log in to reply
 

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