File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 55
55
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
56
56
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
57
57
67|[ Add Binary] ( ./0067-add-binary.js ) |Easy|
58
+ 69|[ Sqrt(x)] ( ./0069-sqrtx.js ) |Medium|
58
59
70|[ Climbing Stairs] ( ./0070-climbing-stairs.js ) |Easy|
59
60
73|[ Set Matrix Zeroes] ( ./0073-set-matrix-zeroes.js ) |Medium|
60
61
74|[ Search a 2D Matrix] ( ./0074-search-a-2d-matrix.js ) |Medium|
You can’t perform that action at this time.
0 commit comments