Solving Sqrt(x) without math.sqrt() using binary search

🧩 Day 54 of #LeetCode365 Problem: 69. Sqrt(x) Category: Binary Search | Math Today’s problem was all about finding square roots… but without using math.sqrt() 😤 — because that’s too easy, right? So I made my own version using binary search. Basically, I played “guess the root” until my code said, “close enough, stop now.” 😎 💻 Approach: 👉 Set l = 0, r = x 👉 Use binary search to narrow down the integer part of √x 👉 Return the best guess (a.k.a. the floor of the real answer) ⚙️ Complexity: ⏱ O(log n) | 💾 O(1) 💡 Lesson: Sometimes you don’t need to know the exact answer — just the closest one that doesn’t crash your code 🤷♂️ #LeetCode #Python #CodingHumor #DSA #BinarySearch #ProgrammerHumor

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories