Skip to content

Commit 5503d98

Browse files
Merge remote-tracking branch 'origin/Jason'
2 parents 7ec1a9e + ff9f1d6 commit 5503d98

9 files changed

+120
-0
lines changed
File renamed without changes.

069(Binary)_Sqrt(x).py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution:
2+
def mySqrt(self, x):
3+
"""
4+
:type x: int
5+
:rtype: int
6+
"""
7+
if 0 == x:
8+
return 0
9+
i = 1
10+
j = x / 2 + 1
11+
while(i <= j):
12+
center = int((i + j) / 2 )
13+
if center ** 2 == x:
14+
return center
15+
elif center ** 2 > x:
16+
j = center - 1
17+
else:
18+
i = center + 1
19+
return j

069(Func)_ Sqrt(x).py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def mySqrt(self, x):
3+
"""
4+
:type x: int
5+
:rtype: int
6+
"""
7+
import math
8+
return int(math.sqrt(x))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
7+
class Solution:
8+
def deleteDuplicates(self, head):
9+
"""
10+
:type head: ListNode
11+
:rtype: ListNode
12+
"""
13+
cur = head
14+
while cur:
15+
while cur.next and cur.val == cur.next.val:
16+
cur.next = cur.next.next
17+
cur = cur.next
18+
return head

088_ Merge Sorted Array.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def merge(self, nums1, m, nums2, n):
3+
"""
4+
:type nums1: List[int]
5+
:type m: int
6+
:type nums2: List[int]
7+
:type n: int
8+
:rtype: void Do not return anything, modify nums1 in-place instead.
9+
"""
10+
while m > 0 and n > 0:
11+
if nums1[m - 1] > nums2[n - 1]:
12+
nums1[m + n - 1] = nums1[m - 1]
13+
m -= 1
14+
else:
15+
nums1[m + n - 1] = nums2[n - 1]
16+
n -= 1
17+
if n > 0:
18+
nums1[:n] = nums2[:n]

100(FK1)_Same Tree.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def isSameTree(self, p, q):
10+
"""
11+
:type p: TreeNode
12+
:type q: TreeNode
13+
:rtype: bool
14+
"""
15+
if p and q:
16+
return (p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right))
17+
return p is q

100_Same Tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def isSameTree(self, p, q):
10+
"""
11+
:type p: TreeNode
12+
:type q: TreeNode
13+
:rtype: bool
14+
"""
15+
if p == None and q == None:
16+
return True
17+
elif p and q and p.val == q.val:
18+
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
19+
return False
20+

100_Same Tree.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution:
9+
def isSameTree(self, p, q):
10+
"""
11+
:type p: TreeNode
12+
:type q: TreeNode
13+
:rtype: bool
14+
"""
15+
if p == None and q == None:
16+
return True
17+
elif p and q and p.val == q.val:
18+
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
19+
return False
20+

0 commit comments

Comments
 (0)