From 034a7daabb0898e09738f2183317e4a213e2f359 Mon Sep 17 00:00:00 2001 From: Shahriar Shatil <52494840+ShatilKhan@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:39:40 +0600 Subject: [PATCH] Time: 71 ms (54.90%) | Memory: 53.1 MB (29.38%) - LeetSync --- 231-power-of-two/power-of-two.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 231-power-of-two/power-of-two.js diff --git a/231-power-of-two/power-of-two.js b/231-power-of-two/power-of-two.js new file mode 100644 index 0000000..c73e8b9 --- /dev/null +++ b/231-power-of-two/power-of-two.js @@ -0,0 +1,21 @@ +/** + * @param {number} n + * @return {boolean} + */ +var isPowerOfTwo = function(n) { + let solution = new Solution(); + return solution.isPowerOfTwo(n); +}; + +class Solution { + isPowerOfTwo(n) { + for (let i = 0; i < 31; i++) { + let ans = Math.pow(2, i); + if (ans === n) { + return true; + } + } + return false; + } +} +