Menu

Post image 1
Post image 2
1 / 2
0

LeetCode Solution: 69. Sqrt(x)

DEV Community·Vansh Aggarwal·about 1 month ago
#1EeUG9Ej
Reading 0:00
15s threshold

✨ Unlocking Sqrt(x) : Your First Dive into Binary Search! 🚀 Hey amazing developers! 👋 Vansh2710 here, ready to embark on another exciting LeetCode adventure with you. Today, we're tackling problem #69: Sqrt(x) . Sounds simple, right? Just find the square root! But here's the twist: we can't use any fancy built-in functions. We're going old-school and building our own square root finder from scratch. Get ready to discover the magic of Binary Search ! 🧐 Problem Explanation: What are we actually doing? The problem asks us to find the square root of a given non-negative integer x . The catch? We need to round down the result to the nearest whole number. So, if sqrt(x) is 2.828... , we return 2 . And a critical constraint: NO built-in functions like pow(x, 0.5) or x ** 0.5 allowed! This means we have to come up with our own algorithm. Let's look at the examples: Example 1: x = 4 The square root of 4 is exactly 2. Output: 2 Example 2: x = 8 The actual square root of 8 is approximately 2.82842...…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More