Skip to content

Commit 6ebeecd

Browse files
committed
2020-07-02
1 parent b1f7d10 commit 6ebeecd

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode(object):
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.left = None
6+
# self.right = None
7+
8+
class Solution(object):
9+
def sortedArrayToBST(self, nums):
10+
"""
11+
:type nums: List[int]
12+
:rtype: TreeNode
13+
"""
14+
if not nums:
15+
return None
16+
mid_idx = len(nums) // 2
17+
root = TreeNode(nums[mid_idx])
18+
root.left = self.sortedArrayToBST(nums[:mid_idx])
19+
root.right = self.sortedArrayToBST(nums[mid_idx + 1:])
20+
21+
return root
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution(object):
2+
def minSubArrayLen(self, s, nums):
3+
"""
4+
:type s: int
5+
:type nums: List[int]
6+
:rtype: int
7+
"""
8+
left = 0
9+
window_sum = 0
10+
res = len(nums)
11+
for right in range(len(nums)):
12+
window_sum += nums[right]
13+
14+
while window_sum >= s:
15+
res = min(res, right - left + 1)
16+
window_sum -= nums[left]
17+
left += 1
18+
return res if sum(nums) >= s else 0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution(object):
2+
def findLength(self, A, B):
3+
"""
4+
:type A: List[int]
5+
:type B: List[int]
6+
:rtype: int
7+
"""
8+
la, lb = len(A), len(B)
9+
10+
dp = [[0 for _ in range(lb + 1)] for _ in range(la + 1)]
11+
12+
res = 0
13+
for i in range(1, la + 1):
14+
for j in range(1, lb + 1):
15+
if A[i - 1] == B[j - 1]:
16+
dp[i][j] = dp[i - 1][j - 1] + 1
17+
res = max(res, dp[i][j])
18+
return res

剑指Offer50.第一个只出现一次的字符/剑指Offer50-第一个只出现一次的字符.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def firstUniqChar(self, s):
55
:rtype: str
66
"""
77
from collections import Counter
8-
98
dic = Counter(s)
109

1110
for ch in s:

面试题16.07.最大数值/面试题16.07-最大数值.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ def maximum(self, a, b):
55
:type b: int
66
:rtype: int
77
"""
8-
return max(a, b)
8+
return max(a, b)

0 commit comments

Comments
 (0)