当前位置:网站首页>Leetcode 1094 car pooling (Analog)
Leetcode 1094 car pooling (Analog)
2022-06-11 01:44:00 【_ TCgogogo_】
There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).
You are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi respectively. The locations are given as the number of kilometers due east from the car's initial location.
Return true if it is possible to pick up and drop off all passengers for all the given trips, or false otherwise.
Example 1:
Input: trips = [[2,1,5],[3,3,7]], capacity = 4 Output: false
Example 2:
Input: trips = [[2,1,5],[3,3,7]], capacity = 5 Output: true
Constraints:
1 <= trips.length <= 1000trips[i].length == 31 <= numPassengersi <= 1000 <= fromi < toi <= 10001 <= capacity <= 105
Topic link :https://leetcode.com/problems/car-pooling/
The main idea of the topic : The capacity of a given vehicle is capacity And the number of passengers in each section , Ask if you can take all the passengers to their destination
Topic analysis : Simulate getting on and off according to the meaning of the question , If the number of people on the train at a certain time is greater than capacity No way.
0ms, Time beats 100%
class Solution {
public boolean carPooling(int[][] trips, int capacity) {
int[] cnt = new int[1005];
int ma = 0, pcur = 0;
for (int i = 0; i < trips.length; i++) {
cnt[trips[i][1]] += trips[i][0];
cnt[trips[i][2]] -= trips[i][0];
ma = Math.max(ma, to);
}
for (int i = 0; i <= ma; i++) {
pcur += cnt[i];
if (pcur > capacity) {
return false;
}
}
return true;
}
}边栏推荐
- Web3生态去中心化金融平台——Sealem Finance
- SAS principal component analysis (finding correlation matrix, eigenvalue, unit eigenvector, principal component expression, contribution rate and cumulative contribution rate, and data interpretation)
- Role of handlermethodargumentresolver + use case
- 立个flag--重构promise
- 如何下载网页照片
- MATLAB随机函数汇总
- IRS application release 16: H5 application design guide
- 【ROS】ROSmsg cakin_ Make compilation error
- 2022.6.6-----leetcode.732
- Introduction to the application process of Shenzhen China Patent Award, with a subsidy of 1million yuan
猜你喜欢

关于概率统计中的排列组合

Once you know these treasure websites, you can't live without them!!!

detectron2训练自己的数据集和转coco格式
![[geometric vision] 4.2 piecewise linear transformation](/img/9e/ad010e0b55c88f2c0244442ae20fb3.jpg)
[geometric vision] 4.2 piecewise linear transformation

Yunna PDA wireless fixed assets inventory management system
![[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields](/img/c6/f1cec6de62e85de446dba7ea8675f0.jpg)
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields

2.2、ROS+PX4仿真多点巡航飞行----正方形
![[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design](/img/63/3193186820215b9babc3d00e1ef20b.jpg)
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design

Project_ Visual analysis of epidemic data based on Web Crawler
![[Li mu] how to read papers [intensive reading of papers]](/img/41/7e1ff1db2f7a848c8702c186c79fe5.jpg)
[Li mu] how to read papers [intensive reading of papers]
随机推荐
SSH Remote Login configuration sshd_ Config file details
2.2. Ros+px4 simulation multi-point cruise flight - Square
1.3 ROS 无人机简介
Leetcode 1814 count nice pairs in an array (recommended by map)
“看似抢票实际抢钱”,别被花式抢票产品一再忽悠
Brief description of custom annotations
ava. Lang.noclassdeffounderror: org/apache/velocity/context/context solution
Introduction to the application process of Shenzhen China Patent Award, with a subsidy of 1million yuan
What are programmers in big factories looking at? It took me two years to sort it out, and I will look at it and cherish it!
1.5、PX4载具选择
Is the SQL query result different from what you expected? Mostly "null" is making trouble
Understanding of multithreading
Inventory management and strategy mode
Multi interest recall model practice | acquisition technology
Once you know these treasure websites, you can't live without them!!!
Using completabilefuture
Set up a flag -- Reconstruct promise
Application of object storage S3 in distributed file system
SAS principal component analysis (finding correlation matrix, eigenvalue, unit eigenvector, principal component expression, contribution rate and cumulative contribution rate, and data interpretation)
Throttling and anti chattering of functions