Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- python xor
- 파이썬릿코드풀기
- 릿코드
- python Leetcode
- leetcode풀기
- python zip_longest
- 알고리즘풀기
- 파이썬릿코드
- binary search
- python priority queue
- python 릿코드
- 릿코드풀이
- 파이썬알고리즘풀기
- 잇츠디모
- python sorted
- 알고리즘풀이
- leetcode 풀기
- leetcode풀이
- 파이썬 알고리즘
- 릿코드풀기
- 릿코드 풀기
- python 알고리즘
- 파이썬 프로그래머스
- LeetCode
- 파이썬 알고리즘 풀기
- 코틀린기초
- 상가수익률계산기
- 릿코드 파이썬
- 파이썬알고리즘
- 파이썬 릿코드
Archives
- Today
- Total
소프트웨어에 대한 모든 것
LeetCode 풀기 - 1094. Car Pooling 본문
반응형
1094. Car Pooling
https://leetcode.com/problems/car-pooling/
Car Pooling - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제)

솔루션1)
class Solution(object):
def carPooling(self, trips, capacity):
"""
:type trips: List[List[int]]
:type capacity: int
:rtype: bool
"""
d = defaultdict(int)
for trip in trips:
d[trip[1]] += trip[0]
d[trip[2]] -= trip[0]
p, s, e = zip(*trips)
occupied = 0
for location in sorted(list(set(s+e))):
occupied += d[location]
if occupied > capacity:
return False
return True
반응형
'알고리즘 > LeetCode' 카테고리의 다른 글
| LeetCode 풀기 - 382. Linked List Random Node (0) | 2022.01.11 |
|---|---|
| LeetCode 풀기 - 67. Add Binary (0) | 2022.01.10 |
| LeetCode 풀기 - 997. Find the Town Judge (0) | 2022.01.04 |
| LeetCode 풀기 - 1026. Maximum Difference Between Node and Ancestor (0) | 2021.12.31 |
| LeetCode 풀기 - 559. Maximum Depth of N-ary Tree (0) | 2021.12.31 |
Comments