Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

401. 二进制手表 #40

Open
zpc7 opened this issue Aug 31, 2022 · 0 comments
Open

401. 二进制手表 #40

zpc7 opened this issue Aug 31, 2022 · 0 comments
Labels
简单 LeetCode 难度定级

Comments

@zpc7
Copy link
Owner

zpc7 commented Aug 31, 2022

401. 二进制手表

/**
 * @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;
}
@zpc7 zpc7 added the 简单 LeetCode 难度定级 label Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
简单 LeetCode 难度定级
Projects
None yet
Development

No branches or pull requests

1 participant