forked from azl397985856/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
简单LeetCode 难度定级LeetCode 难度定级
Description
/**
* @param {number} turnedOn
* @return {string[]}
*/
var readBinaryWatch = function (turnedOn) {
const ans = [];
if (turnedOn > 8) return ans;
const getBinaryCount = num => num.toString(2).split('').filter(item => item !== '0').length;
for (let h = 0; h < 12; h++) {
for (let m = 0; m < 60; m++) {
if (getBinaryCount(h) + getBinaryCount(m) === turnedOn) {
ans.push(h + ":" + (m < 10 ? "0" : "") + m);
}
}
}
return ans;
}
Metadata
Metadata
Assignees
Labels
简单LeetCode 难度定级LeetCode 难度定级