LeetCode: Reverse Bits Solution
String manipulationApproach
Convert n
to binary string
Make the string 32 in length by padding with 0
Reverse the string
Convert back to decimal
Implementation
1var reverseBits = function (n) {2 return parseInt(3 n.toString(2).padStart(32, "0").split("").reverse().join(""),4 25 )6}
References
Comments
Loading comments...
Tags
leetcode
string
bit manipulation
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
CSSBattle 15.84: Junction
Grid, transforms, flip
Previous Post
LeetCode: House Robber
Memoized recusion