[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/tech/ - Technical SEO

Site architecture, schema markup & core web vitals
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1771376890415.jpg (42.15 KB, 1280x720, img_1771376881471_4zzwybm9.jpg)ImgOps Exif Google Yandex

a303f No.1234

so i found this cool leetcode problem: binary number with alternating bits - 693. it's about checking if a num's bin rep has adjacent bit flips without loops.

basically, you're given an int and need to return true only when the nums in its binary form alternate between zeros & ones (e. g, '10' or even long like.
"452687394".
).

i tried it out with c++, python + js. turns tricky but super fun! i used bitwise ops and some clever tricks to make the solution work.

so, here's a quick take:
- use `&` & bit shifting
- check if flips match pattern

anyone else played around w/ this one? how'd it go for you?

ps: wondering about best ways to test these kinds of problems. any tips or gotchas?
gotcha : watch out for edge cases like single-digit nums!

https://dev.to/om_shree_0709/beginner-friendly-guide-binary-number-with-alternating-bits-leetcode-693-c-python-2aco


[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">