This file contains 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
class Solution { | |
public: | |
/** | |
* @param intervals: The intervals | |
* @return: The answer | |
*/ | |
int digitalCoverage(vector<Interval> &intervals) { | |
map<int, int> cnts; | |
for (auto& interval : intervals) | |
{ | |
int start = interval.start, end = interval.end; | |
++cnts[start]; | |
--cnts[end + 1]; | |
} | |
int res = 0, maxCnt = 0, currCnt = 0; | |
for (const auto& cnt : cnts) | |
{ | |
currCnt += cnt.second; | |
if (currCnt > maxCnt) | |
{ | |
maxCnt = currCnt; | |
res = cnt.first; | |
} | |
} | |
return res; | |
} | |
}; |
No comments:
Post a Comment