Skip to content

Commit ff4ec9c

Browse files
committed
update
1 parent d2670d3 commit ff4ec9c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Array/1094. Car Pooling.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
The key to this type of higest resource using question is to find out where is the max and if the max exceed the limitation
3+
So we can order (by position) all the resource use and free actions like [position 1, + N] [position 2, -N]
4+
And for all the items in this list, the current position resource occupation is just the sum of item[1]
5+
If we see a number exceed the limit, return
6+
'''
7+
8+
class Solution:
9+
def carPooling(self, trips: List[List[int]], capacity: int) -> bool:
10+
orders=[]
11+
for p, st, en in trips:
12+
orders.append((st,p))
13+
orders.append((en,-p))
14+
15+
orders.sort()
16+
p=0
17+
for item in orders:
18+
p += item[1]
19+
if p > capacity:
20+
return False
21+
22+
return True
23+
24+
25+

Array/303. Range Sum Query - Immutable.py

Whitespace-only changes.

0 commit comments

Comments
 (0)