Compare commits
No commits in common. "c5c82a3ba1eb37819e4251164d6a89b013b0fee6" and "57878d980d3e95f94d56faa663cde0f8ed2e9207" have entirely different histories.
c5c82a3ba1
...
57878d980d
@ -1,35 +0,0 @@
|
|||||||
def maxSatisfied(customers, grumpy, minutes):
|
|
||||||
"""
|
|
||||||
:type customers: List[int]
|
|
||||||
:type grumpy: List[int]
|
|
||||||
:type minutes: int
|
|
||||||
:rtype: int
|
|
||||||
"""
|
|
||||||
# Sliding Window Approach
|
|
||||||
i = 0
|
|
||||||
j = 0
|
|
||||||
sum_unsatisfied = 0
|
|
||||||
max_sum = float('-inf')
|
|
||||||
|
|
||||||
# Using sliding window
|
|
||||||
while j < len(grumpy):
|
|
||||||
if grumpy[j] == 1: # Calculation part
|
|
||||||
sum_unsatisfied += customers[j]
|
|
||||||
|
|
||||||
if j - i + 1 < minutes:
|
|
||||||
j += 1
|
|
||||||
elif j - i + 1 == minutes:
|
|
||||||
max_sum = max(max_sum, sum_unsatisfied)
|
|
||||||
if grumpy[i] == 1: # Removing calculation part using i
|
|
||||||
sum_unsatisfied -= customers[i]
|
|
||||||
i += 1 # Sliding the window
|
|
||||||
j += 1
|
|
||||||
|
|
||||||
for k in range(len(customers)): # Now finding only satisfied customers (grumpy[k] == 0)
|
|
||||||
if grumpy[k] == 0:
|
|
||||||
max_sum += customers[k]
|
|
||||||
|
|
||||||
return max_sum
|
|
||||||
|
|
||||||
|
|
||||||
maxSatisfied([1,0,1,2,1,1,7,5], [0,1,0,1,0,1,0,1], 3)
|
|
||||||
@ -1,19 +1,8 @@
|
|||||||
def plusOne(digits):
|
def plusOne(digits):
|
||||||
zeros = 0
|
zeros = 0
|
||||||
if digits[-1] == 9:
|
if digits[-1] == 9:
|
||||||
if len(digits) < 2:
|
|
||||||
digits[-1] = 1
|
digits[-1] = 1
|
||||||
digits.append(0)
|
digits.append(0)
|
||||||
return digits
|
|
||||||
for i in range(len(digits)):
|
|
||||||
if digits[i] == 9:
|
|
||||||
zeros += 1
|
|
||||||
if digits[i-1] == 9:
|
|
||||||
digits[i] = 0
|
|
||||||
else:
|
|
||||||
digits[i] = 1
|
|
||||||
break
|
|
||||||
digits.append(0)
|
|
||||||
else:
|
else:
|
||||||
digits[-1] = digits[-1] + 1
|
digits[-1] = digits[-1] + 1
|
||||||
return digits
|
return digits
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user