From 256e1c048c4a350d53dd74dc93e25a784e61066a Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Jul 2019 11:06:55 +0800 Subject: [PATCH] add 1109 --- README.md | 3 ++- src/1109-Corporate-Flight-Bookings/1109.cpp | 18 ++++++++++++++++++ src/1109-Corporate-Flight-Bookings/1109.go | 11 +++++++++++ src/1109-Corporate-Flight-Bookings/1109.py | 9 +++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/1109-Corporate-Flight-Bookings/1109.cpp create mode 100644 src/1109-Corporate-Flight-Bookings/1109.go create mode 100644 src/1109-Corporate-Flight-Bookings/1109.py diff --git a/README.md b/README.md index 089c0c9d..7cab59c9 100644 --- a/README.md +++ b/README.md @@ -441,4 +441,5 @@ LeetCode |1104|[Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/) | c | [c++](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.cpp) |[python](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.py)|[go](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.go)||Easy| |1105|[Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | c | [c++](./src/1105-Filling-Bookcase-Shelves/1105.cpp) |[python](./src/1105-Filling-Bookcase-Shelves/1105.py)|[go](./src/1105-Filling-Bookcase-Shelves/1105.go)||Medium| |1106|[Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression/) | c | [c++](./src/1106-Parsing-A-Boolean-Expression/1106.cpp) |[python](./src/1106-Parsing-A-Boolean-Expression/1106.py)|[go](./src/1106-Parsing-A-Boolean-Expression/1106.go)||Hard| -|1108|[Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/) | c | [c++](./src/1108-Defanging-an-IP-Address/1108.cpp) |[python](./src/1108-Defanging-an-IP-Address/1108.py)|[go](./src/1108-Defanging-an-IP-Address/1108.go)||Easy| \ No newline at end of file +|1108|[Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/) | c | [c++](./src/1108-Defanging-an-IP-Address/1108.cpp) |[python](./src/1108-Defanging-an-IP-Address/1108.py)|[go](./src/1108-Defanging-an-IP-Address/1108.go)||Easy| +|1109|[iCorporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings/) | c | [c++](./src/1109-Corporate-Flight-Bookings/1109.cpp) |[python](./src/1109-Corporate-Flight-Bookings/1109.py)|[go](./src/1109-Corporate-Flight-Bookings/1109.go)||Medium| \ No newline at end of file diff --git a/src/1109-Corporate-Flight-Bookings/1109.cpp b/src/1109-Corporate-Flight-Bookings/1109.cpp new file mode 100644 index 00000000..3c7064d9 --- /dev/null +++ b/src/1109-Corporate-Flight-Bookings/1109.cpp @@ -0,0 +1,18 @@ +class Solution +{ +public: + vector corpFlightBookings(vector>& bookings, int n) + { + vector res(n + 1, 0); + for (auto& book : bookings) + { + res[book[0]-1] += book[2]; + res[book[1]] -= book[2]; + } + for (int i = 1; i <= n; ++i) + { + res[i] += res[i-1]; + } + return {res.begin(), res.end()-1}; + } +}; \ No newline at end of file diff --git a/src/1109-Corporate-Flight-Bookings/1109.go b/src/1109-Corporate-Flight-Bookings/1109.go new file mode 100644 index 00000000..33e7e1d1 --- /dev/null +++ b/src/1109-Corporate-Flight-Bookings/1109.go @@ -0,0 +1,11 @@ +func corpFlightBookings(bookings [][]int, n int) []int { + res := make([]int, n + 1) + for _, book := range bookings { + res[book[0]-1] += book[2] + res[book[1]] -= book[2] + } + for i := 1; i <= n; i++ { + res[i] += res[i-1] + } + return res[:n] +} \ No newline at end of file diff --git a/src/1109-Corporate-Flight-Bookings/1109.py b/src/1109-Corporate-Flight-Bookings/1109.py new file mode 100644 index 00000000..102b6f79 --- /dev/null +++ b/src/1109-Corporate-Flight-Bookings/1109.py @@ -0,0 +1,9 @@ +class Solution: + def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]: + res = [0] * (n + 1) + for i, j, k in bookings: + res[i-1] += k + res[j] -= k + for i in range(1, len(res)): + res[i] += res[i-1] + return res[:-1] \ No newline at end of file