Skip to content

Commit 0756298

Browse files
committed
Leetcode 69
Python Solution
1 parent ece041d commit 0756298

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Personal Practice Set - Doing One a Day (sometimes) in a Variety of Languages!!
3535
| 54 | Medium | [Spiral Matrix](leetcode/54-Medium-Spiral-Matrix/problem.md) | [Python](leetcode/54-Medium-Spiral-Matrix/answer.py) |
3636
| 58 | Easy | [Length of Last Word](leetcode/58-Easy-Length-Of-Last-Word/problem.md) | [Python](leetcode/58-Easy-Length-Of-Last-Word/answer.py) |
3737
| 66 | Easy | [Plus One](leetcode/66-Easy-Plus-One/problem.md) | [Python](leetcode/66-Easy-Plus-One/answer.py) |
38+
| 69 | Easy | [Sqrt()](leetcode/69-Easy-Sqrt/problem.md) | [Python](leetcode/69-Easy-Sqrt/answer.py) |
3839
| 70 | Easy | [Climbing Stairs](leetcode/70-Easy-Climbing-Stairs/problem.md) | [C](leetcode/70-Easy-Climbing-Stairs/answer.c) |
3940
| 83 | Easy | [Remove Duplicates from Sorted List](leetcode/83-Easy-Remove-Duplicates-From-Sorted-List/problem.md) | [Python](leetcode/83-Easy-Remove-Duplicates-From-Sorted-List/answer.py)|
4041
| 100| Easy | [Same Tree](leetcode/100-Easy-Same-Tree/problem.md) | [Python](leetcode/100-Easy-Same-Tree/answer.py) |

leetcode/69-Easy-Sqrt/answer.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
#-------------------------------------------------------------------------------
4+
class Solution(object):
5+
def mySqrt(self, x):
6+
"""
7+
:type x: int
8+
:rtype: int
9+
"""
10+
r = x
11+
while r*r > x:
12+
r = (r + x/r) / 2
13+
return r
14+
#-------------------------------------------------------------------------------
15+
# Testing

leetcode/69-Easy-Sqrt/problem.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Problem 69: Sqrt()
2+
3+
4+
#### Difficulty: Easy
5+
6+
#### Problem
7+
8+
Implement int sqrt(int x).
9+
10+
Compute and return the square root of x.
11+
12+
x is guaranteed to be a non-negative integer.
13+
14+
#### Example
15+
16+
<pre>
17+
18+
Input: 4
19+
Output: 2
20+
21+
Input: 8
22+
Output: 2
23+
Explanation: The square root of 8 is 2.82842..., and since we want to return an integer, the decimal part will be truncated.
24+
25+
26+
</pre>

0 commit comments

Comments
 (0)