forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 1
[pull] master from wisdompeak:master #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
Greedy/2345.Finding-the-Number-of-Visible-Mountains/Readme.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
### 2345.Finding-the-Number-of-Visible-Mountains | ||
|
||
本题的突破点在于这个发现:如果三角形A的左端点早于三角形B的左端点,那么A一定不会被B覆盖。所以将所有的三角形按照左端点排序,那我们能看到的三角形的顺序一定不会违反这个序列。 | ||
|
||
接下来思考,虽然A不会被B覆盖,但是B依然可能会被A覆盖。如何判定呢?其实就取决于A的右端点是否足够远。如果A的右端点足够远,那么它有可能还会覆盖后续的若干个三角形。 | ||
|
||
所以基本思想就是,将所有三角形按照左端点排序,遍历每个三角形的时候维护当前最远的右端点的位置far。任何新的三角形的右端点的位置如果在far前面,就说明它是会被前面的三角形所覆盖的。 | ||
|
||
本题的corner case是,如果有两个三角形的左端点相同,那如何排序?不难想到,我们先处理右端点更远的,这样就保证它能把其他的三角形给遮盖了。 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.