File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 3
3
## Easy
4
4
| S.no.| Question| Solution|
5
5
| ---| ------------| ------------|
6
- | 1| [ Square Root] ( https://leetcode.com/problems/sqrtx/ ) | Pending |
6
+ | 1| [ Square Root] ( https://leetcode.com/problems/sqrtx/ ) | [ Solution ] ( sqrt.cpp ) |
7
7
| 2| [ First Bad Version] ( https://leetcode.com/problems/first-bad-version/ ) | Pending|
8
8
| 3| [ Two Sum II - Input array is sorted] ( https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ ) | Pending|
9
9
| 4| [ Valid Perfect Square] ( https://leetcode.com/problems/valid-perfect-square/ ) | Pending|
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ int mySqrt (int x)
5
+ {
6
+ int low = 0 , high = x;
7
+ long mid;
8
+ while (low <= high)
9
+ {
10
+ mid = low + (high - low) / 2 ;
11
+ if (mid * mid <= x)
12
+ low = mid + 1 ;
13
+ else
14
+ high = mid - 1 ;
15
+ }
16
+ return low - 1 ;
17
+ }
18
+
19
+ int main ()
20
+ {
21
+ int t;
22
+ cin >> t;
23
+ while (t--)
24
+ {
25
+ int n;
26
+ cin >> n;
27
+ cout<<mySqrt (n)<<endl;
28
+ }
29
+ return 0 ;
30
+ }
You can’t perform that action at this time.
0 commit comments