Skip to content

Commit f5362f3

Browse files
committed
Add solution #69
1 parent 374d4ee commit f5362f3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

0069-sqrtx.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 69. Sqrt(x)
3+
* https://leetcode.com/problems/sqrtx/
4+
* Difficulty: Medium
5+
*
6+
* Given a non-negative integer x, return the square root of x rounded down to the nearest
7+
* integer. The returned integer should be non-negative as well.
8+
*
9+
* You must not use any built-in exponent function or operator.
10+
*/
11+
12+
/**
13+
* @param {number} x
14+
* @return {number}
15+
*/
16+
var mySqrt = function(x) {
17+
let result = 1;
18+
19+
while (result * result <= x) {
20+
result++;
21+
}
22+
23+
return result - 1;
24+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
58|[Length of Last Word](./0058-length-of-last-word.js)|Easy|
5656
66|[Plus One](./0066-plus-one.js)|Easy|
5757
67|[Add Binary](./0067-add-binary.js)|Easy|
58+
69|[Sqrt(x)](./0069-sqrtx.js)|Medium|
5859
70|[Climbing Stairs](./0070-climbing-stairs.js)|Easy|
5960
73|[Set Matrix Zeroes](./0073-set-matrix-zeroes.js)|Medium|
6061
74|[Search a 2D Matrix](./0074-search-a-2d-matrix.js)|Medium|

0 commit comments

Comments
 (0)