Skip to content

Commit 775ef0c

Browse files
committed
2020-07-20
1 parent 328a407 commit 775ef0c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution(object):
2+
def runningSum(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: List[int]
6+
"""
7+
s = 0
8+
res = []
9+
for num in nums:
10+
s += num
11+
res.append(s)
12+
return res
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution(object):
2+
def findLeastNumOfUniqueInts(self, arr, k):
3+
"""
4+
:type arr: List[int]
5+
:type k: int
6+
:rtype: int
7+
"""
8+
if not arr or len(arr) == k:
9+
return 0
10+
from collections import Counter
11+
dic = Counter(arr)
12+
l = dic.values()
13+
l = sorted(l)[::-1]
14+
15+
target = len(arr) - k
16+
s = 0
17+
for i, num in enumerate(l):
18+
s += num
19+
if s >= target:
20+
return i + 1
21+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution(object):
2+
def minDays(self, bloomDay, m, k):
3+
"""
4+
:type bloomDay: List[int]
5+
:type m: int
6+
:type k: int
7+
:rtype: int
8+
"""
9+
if m * k > len(bloomDay):
10+
return -1
11+
12+
left, right = 1, max(bloomDay)
13+
while left <= right:
14+
mid = (left + right) // 2
15+
# print mid
16+
flowerCnt = 0
17+
dayCnt = 0
18+
for day in bloomDay:
19+
if day <= mid:
20+
dayCnt += 1
21+
if dayCnt >= k:
22+
flowerCnt += 1
23+
dayCnt = 0
24+
else:
25+
dayCnt = 0
26+
# print flowerCnt
27+
if flowerCnt >= m:
28+
right = mid - 1
29+
else:
30+
left = mid + 1
31+
return left
32+

0 commit comments

Comments
 (0)