Skip to content

Commit

Permalink
https://leetcode.com/contest/weekly-contest-237
Browse files Browse the repository at this point in the history
  • Loading branch information
zxzl committed Apr 18, 2021
1 parent 55d3753 commit 5ec5339
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/1832-check-if-the-sentence-is-pangram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def checkIfPangram(self, sentence: str) -> bool:

return len(set(sentence)) == 26
16 changes: 16 additions & 0 deletions python/1833-maximum-ice-cream-bars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def maxIceCream(self, costs: List[int], coins: int) -> int:
costs.sort()

balance = coins

n = 0

for c in costs:
if balance >= c:
n += 1
balance -= c
else:
break

return n
37 changes: 37 additions & 0 deletions python/1834-single-threaded-cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import heapq


class Solution:
def getOrder(self, tasks: List[List[int]]) -> List[int]:

# (t, duration, i)
events = []

# (duration, i)
pending = []

logs = []

for (i, task) in enumerate(tasks):
heapq.heappush(events, [task[0], task[1], i])

# print(events)

e = heapq.heappop(events)
logs.append(e[2])
events.append([e[0] + e[1], float('inf')])

while len(events) > 0:
e = heapq.heappop(events)
# print(e)
if e[1] == float('inf'): # a process ended
if len(pending) == 0:
break

new_task = heapq.heappop(pending)
heapq.heappush(events, [new_task[0] + e[0], float('inf')])
logs.append(new_task[1])
else: # add process to q
heapq.heappush(pending, [e[1], e[2]])

return logs
12 changes: 12 additions & 0 deletions python/1835-find-xor-sum-of-all-pairs-bitwise-and.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def getXORSum(self, arr1: List[int], arr2: List[int]) -> int:

ca = 0
for a in arr1:
ca = ca ^ a

cb = 0
for b in arr2:
cb = cb ^ b

return ca & cb

0 comments on commit 5ec5339

Please sign in to comment.