leetcode-1109-差分

奋斗吧
奋斗吧
擅长邻域:未填写

标签: leetcode-1109-差分 Python博客 51CTO博客

2023-04-07 18:23:54 122浏览

leetcode-1109-差分,classSolution{publicint[]corpFlightBookings(int[][]bookings,intn){int[]diff=newint[n];for(int[]booking:bookings){intfirst=booking[0],last=boo



class Solution {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] diff = new int[n];
        for (int[] booking : bookings) {
            int first = booking[0], last = booking[1], seats = booking[2];
            diff[first-1] += seats;
            if (last < n) {
                diff[last] -= seats;
            }
        }
        
        int[] passengers = new int[n];
        passengers[0] = diff[0];
        for (int i = 1; i < n; i++) {
            passengers[i] = passengers[i-1] + diff[i];
        }
        
        return passengers;
    }
}



好博客就要一起分享哦!分享海报

此处可发布评论

评论(0展开评论

暂无评论,快来写一下吧

展开评论

您可能感兴趣的博客

客服QQ 1913284695