Skip to content

Commit

Permalink
add 1109
Browse files Browse the repository at this point in the history
  • Loading branch information
luliyucoordinate committed Jul 10, 2019
1 parent 2fc5829 commit 256e1c0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
|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|
18 changes: 18 additions & 0 deletions src/1109-Corporate-Flight-Bookings/1109.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution
{
public:
vector<int> corpFlightBookings(vector<vector<int>>& bookings, int n)
{
vector<int> 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};
}
};
11 changes: 11 additions & 0 deletions src/1109-Corporate-Flight-Bookings/1109.go
Original file line number Diff line number Diff line change
@@ -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]
}
9 changes: 9 additions & 0 deletions src/1109-Corporate-Flight-Bookings/1109.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 256e1c0

Please sign in to comment.