็
งๅๆฌ 252, 56 ็ๆ่ทฏไพๅ็่ฉฑ....ๅช้ๅฐ start ๆๅบ, ็็ขบๆฏ็ฌฆๅ้ๅcase
ไฝไธ็ฌฆๅ ex2, ้ๆจฃ่ท, count ๆๆฏ 0, ๆ่ฉฒ้ ๆณ, ๅ
ไฝไธๅ room , ไฝ้ๆจฃ ex1 ๆ้ฏ
ๅฎๅฎ้ๅฐ start ๆๅบๆฏไธๅค ็, ไปฅไธๆฏ้ฏ็
1.separately sort start, sort end
ๆ่ฉฒๆฏ่ฆๆนๆ้ๆจฃๆณ
start
| | | |
end
| | | |
start ่ตฐๅฐ index 0, 1 ๆ, ้ฝๅฐๆผ min end
before min end, there are two starts, means 2 rooms are required, count = 2
when start ๅฐ index 2 ๆ, ๅทฒ็ถๆฏ min end ๅคง, ไปฃ่กจๆไธๅๆฟ้็ตๆไบ, ๆไปฅไธ้่ฆๆดๅค room,
็ถญๆ count = 2, so min end index++
O(logn), O(n)
้ๆ่ฉฒๆฏๆๅฅฝๅฏซ็ line sweep, ๅๅฏฆ็จ
time: O(nlogn)
space: O(n)
time : O(nlogn)
space: O(h), heap size, <= n