|
1 | 1 | # [1840.Maximum Building Height][title] |
2 | 2 |
|
3 | | -> [!WARNING|style:flat] |
4 | | -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 | | -
|
6 | 3 | ## Description |
| 4 | +You want to build `n` new buildings in a city. The new buildings will be built in a line and are labeled from `1` to `n`. |
| 5 | + |
| 6 | +However, there are city restrictions on the heights of the new buildings: |
| 7 | + |
| 8 | +- The height of each building must be a non-negative integer. |
| 9 | +- The height of the first building **must** be `0`. |
| 10 | +- The height difference between any two adjacent buildings **cannot exceed** `1`. |
| 11 | + |
| 12 | +Additionally, there are city restrictions on the maximum height of specific buildings. These restrictions are given as a 2D integer array `restrictions` where `restrictions[i] = [idi, maxHeighti]` indicates that building `idi` must have a height **less than or equal to** `maxHeighti`. |
| 13 | + |
| 14 | +It is guaranteed that each building will appear **at most once** in `restrictions`, and building `1` will **not** be in `restrictions`. |
| 15 | + |
| 16 | +Return the **maximum possible height** of the **tallest** building. |
7 | 17 |
|
8 | | -**Example 1:** |
| 18 | +**Example 1:** |
| 19 | + |
| 20 | + |
9 | 21 |
|
10 | 22 | ``` |
11 | | -Input: a = "11", b = "1" |
12 | | -Output: "100" |
| 23 | +Input: n = 5, restrictions = [[2,1],[4,1]] |
| 24 | +Output: 2 |
| 25 | +Explanation: The green area in the image indicates the maximum allowed height for each building. |
| 26 | +We can build the buildings with heights [0,1,2,1,2], and the tallest building has a height of 2. |
13 | 27 | ``` |
14 | 28 |
|
15 | | -## 题意 |
16 | | -> ... |
| 29 | +**Example 2:** |
17 | 30 |
|
18 | | -## 题解 |
| 31 | + |
19 | 32 |
|
20 | | -### 思路1 |
21 | | -> ... |
22 | | -Maximum Building Height |
23 | | -```go |
24 | 33 | ``` |
| 34 | +Input: n = 6, restrictions = [] |
| 35 | +Output: 5 |
| 36 | +Explanation: The green area in the image indicates the maximum allowed height for each building. |
| 37 | +We can build the buildings with heights [0,1,2,3,4,5], and the tallest building has a height of 5. |
| 38 | +``` |
| 39 | + |
| 40 | +**Example 3:** |
25 | 41 |
|
| 42 | + |
| 43 | + |
| 44 | +``` |
| 45 | +Input: n = 10, restrictions = [[5,3],[2,5],[7,4],[10,3]] |
| 46 | +Output: 5 |
| 47 | +Explanation: The green area in the image indicates the maximum allowed height for each building. |
| 48 | +We can build the buildings with heights [0,1,2,3,3,4,4,5,4,3], and the tallest building has a height of 5. |
| 49 | +``` |
26 | 50 |
|
27 | 51 | ## 结语 |
28 | 52 |
|
|
0 commit comments