Skip to content

Commit 535df8f

Browse files
committed
Add Python 13 14 15 solution
1 parent 0823fdf commit 535df8f

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution(object):
2+
def longestOnes(self, nums, k):
3+
"""
4+
:type nums: List[int]
5+
:type k: int
6+
:rtype: int
7+
"""
8+
left ,right = 0,0
9+
res = 0
10+
while(right<len(nums)):
11+
if(nums[right] == 0):
12+
k-=1
13+
right+=1
14+
while(k<0):
15+
if(nums[left]==0):
16+
k+=1
17+
left+=1
18+
res = max(res,right-left)
19+
return res
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution(object):
2+
def searchMatrix(self, matrix, target):
3+
"""
4+
:type matrix: List[List[int]]
5+
:type target: int
6+
:rtype: bool
7+
"""
8+
k = 0
9+
10+
for i in range(len(matrix)):
11+
if(target == matrix[i][0]): return True
12+
if(target> matrix[i][0]): k = i
13+
for j in range(1,len(matrix[k])):
14+
if(target == matrix[k][j]): return True
15+
return False
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution(object):
2+
def maximumTastiness(self, price, k):
3+
"""
4+
:type price: List[int]
5+
:type k: int
6+
:rtype: int
7+
"""
8+
price.sort()
9+
def check(d):
10+
cnt, x0 = 1, price[0]
11+
for x in price:
12+
if x - x0 >= d:
13+
cnt += 1
14+
x0 = x
15+
return cnt >= k
16+
17+
left = 0
18+
right = price[-1]-price[0]
19+
while(left < right):
20+
mid = (left+right+1)//2
21+
if check(mid): left = mid
22+
else: right = mid-1
23+
return left

0 commit comments

Comments
 (0)