航班预定统计

https://leetcode.cn/problems/corporate-flight-bookings/description/

int* corpFlightBookings(int** bookings, int bookingsSize, int* bookingsColSize, int n, int* returnSize) {
*returnSize=n;
int *num=(int )calloc(n,sizeof(int));
int diff[n+1];
memset(diff,0,(n+1)
sizeof(int));
for(int i=0;i<bookingsSize;i++){
diff[bookings[i][0]-1]+=bookings[i][2];
diff[bookings[i][1]]-=bookings[i][2];
}
num[0]=diff[0];
for(int i=1;i<n;i++)
num[i]=diff[i]+num[i-1];
return num;

}

posted @ 2024-11-19 20:48  BiankaShenhen  阅读(5)  评论(0编辑  收藏  举报