forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 1
[pull] master from wisdompeak:master #1
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
jenningsloy318
merged 62 commits into
AlgorithmAndLeetCode:master
from
wisdompeak:master
May 27, 2022
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
14905de
Update Readme.md
wisdompeak bf36143
Update Readme.md
wisdompeak f4c967f
Update 732.My-Calendar-III.cpp
wisdompeak 8f0936e
Update Readme.md
wisdompeak 4f2379f
Update 253.Meeting-Rooms-II_v2.cpp
wisdompeak 6b48384
Update Readme.md
wisdompeak 0e98ccd
Update Readme.md
wisdompeak 4674eea
Create 2272.Substring-With-Largest-Variance.cpp
wisdompeak 1c66e00
Update Readme.md
wisdompeak af821e3
Create Readme.md
wisdompeak 63cba92
Update Readme.md
wisdompeak ed7bc1e
Update 493.Reverse-Pairs_v1.cpp
wisdompeak ef946d6
Create 2272.Substring-With-Largest-Variance_v2.cpp
wisdompeak c3ede06
Update Readme.md
wisdompeak e22071e
Update Readme.md
wisdompeak 91f879a
Create 2271.Maximum-White-Tiles-Covered-by-a-Carpet.cpp
wisdompeak 6ffef9d
Update Readme.md
wisdompeak 5457818
Create Readme.md
wisdompeak cc1fd3d
Create 2275.Largest-Combination-With-Bitwise-AND-Greater-Than-Zero.cpp
wisdompeak b4faf37
Update Readme.md
wisdompeak f2d87dd
Create Readme.md
wisdompeak 646a399
Create 2276.Count-Integers-in-Intervals.cpp
wisdompeak 2d20c78
Update Readme.md
wisdompeak 219555d
Update Readme.md
wisdompeak 677cff4
Update Readme.md
wisdompeak 0df9bde
Update Readme.md
wisdompeak 8c34a2b
Create Readme.md
wisdompeak 3fa97d9
Create 1893.Check-if-All-the-Integers-in-a-Range-Are-Covered.cpp
wisdompeak 5e1f37b
Update Readme.md
wisdompeak 8619c6d
Create Readme.md
wisdompeak dccf2d9
Update Readme.md
wisdompeak 0626bc0
Update 351.Android-Unlock-Patterns.cpp
wisdompeak 7b1f152
Update 2015.Average-Height-of-Buildings-in-Each-Segment.cpp
wisdompeak 91c33cf
Update Readme.md
wisdompeak cfdfb66
Update 2015.Average-Height-of-Buildings-in-Each-Segment.cpp
wisdompeak d4c4f58
Update 2158.Amount-of-New-Area-Painted-Each-Day.cpp
wisdompeak 7545bae
Update Readme.md
wisdompeak 3a30051
Create 930.Binary-Subarrays-With-Sum_v2.cpp
wisdompeak 188a295
Update Readme.md
wisdompeak 74d918a
Update Readme.md
wisdompeak 416f6d1
Update 218.The-Skyline-Problem.cpp
wisdompeak 0518651
Update Readme.md
wisdompeak bb6a000
Update Readme.md
wisdompeak 322c53c
Create 2237.Count-Positions-on-Street-With-Required-Brightness.cpp
wisdompeak 98a3d37
Update Readme.md
wisdompeak 280e09c
Create Readme.md
wisdompeak 240128f
Create 490.The-Maze.cpp
wisdompeak 9461f77
Update Readme.md
wisdompeak 1af2dae
Create Readme.md
wisdompeak fef2ba8
Create 6077.Sum-of-Total-Strength-of-Wizards.cpp
wisdompeak afcbc26
Update Readme.md
wisdompeak d7b3e14
Create Readme.md
wisdompeak cf23f97
Update Readme.md
wisdompeak 668082c
Update Readme.md
wisdompeak c84c8d2
Update and rename Others/6077.Sum-of-Total-Strength-of-Wizards/6077.S...
wisdompeak 89d0265
Rename Others/6077.Sum-of-Total-Strength-of-Wizards/Readme.md to Othe...
wisdompeak 78d4974
Update Readme.md
wisdompeak 6e82c3f
Update Readme.md
wisdompeak 6b77c0c
Update Readme.md
wisdompeak 19a16e8
Create 2280.Minimum-Lines-to-Represent-a-Line-Chart.cpp
wisdompeak 7c5183f
Update Readme.md
wisdompeak 3b50e51
Create Readme.md
wisdompeak 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
Next
Next commit
Update Readme.md
- Loading branch information
commit 14905de12c923709ade72c785d093f365bf5ec2c
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
Others/056.Merge-Intervals/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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
### 056.Merge-Intervals | ||
|
||
和252类似的解题手法. | ||
对于区间合并的题目,一般都会采用和252类似的"扫描线"算法。对于每一个区间[a,b],我们在a时刻记录+1,在b时刻记录-1. 然后我们再在时间轴上顺次遍历每一个时间点,统计这些+1和-1的总和。我们会发现当sum从0变为正数时,意味着一个merged interval的开始;当sum从正数变成0时,意味着一个merged interval的结束。这样就巧妙地把所有存在overlap的区间都合并到了一起。 | ||
|
||
需要注意的是,此题中的有效区间长度可以为0,即[t,t]也是合法的,所以在数组q中,我们除了按时间排序之外,第二指标应该按照先1后-1的次序.即如果遇到相同的时刻,{start,1}要比{end,-1}先进行处理,这样就能顺利地包容[t,t]这样的区间. | ||
需要注意的是,对于相同的时刻,如果同时存在多个+1或者-1,应该先处理+1后处理-1。比如[a,b]和[b,c]两个区间,在处理b时刻时,按照先+1再-1的顺序,就不会出现sum=0的情况了,也就避免了merged interval在b处断开。 | ||
|
||
|
||
[Leetcode Link](https://leetcode.com/problems/merge-intervals) | ||
[Leetcode Link](https://leetcode.com/problems/merge-intervals) |
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.