LeetCode 1404. Number of Steps to Reduce a Number in Binary Representation to One — JavaScript

Gary Huang
Traveling Light Taipei
May 29, 2024
Microsoft launches Copilot for Telegram in beta; the bot is limited to text-based requests and cannot generate images for now

https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one/description/

領500元現金了嗎? 點選我的連結成功開樂天帳戶+登入樂天網銀APP,拿500元現金! 樂天帳戶好康在這 : · 使用行動支付5次,享次月活儲年息1.35%存額無上限 · VIP享每月免費跨提/轉共16次 · 提領日幣手續費優惠8次/月 (推薦序號: JGONGL)
https://www.rakuten-bank.com.tw/s/R775

var numSteps = function(s) {
let num = BigInt('0b' + s), ans = 0
while(num>1n) {
num = num%2n ? num+1n : num/2n
ans+=1
}
return ans
};

Using BigInt to avoid number overflow in JS

日本山形 HIPHOP街舞 The Feast — ISHONE / FunkyGary / Japan -Yamagata

--

--

Gary Huang
Traveling Light Taipei

自學程式,目前爲 React 前端工程師,兼職線上課程業師,協助程式自學者就業。熱愛旅遊,將近 30 個國家。訂閱我的旅行與街舞 YT :https://www.youtube.com/channel/UCEU-bEDl7R-iGyLVZFae33g