leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0436.cpp (468B)
0 class Solution { 1 public: 2 vector<int> findRightInterval(const vector<vector<int>> &intervals) const { 3 const int n = size(intervals); 4 vector<int> res(n); 5 map<int, int> mp; 6 7 for (int i = 0; i < n; i++) 8 mp[intervals[i][0]] = i; 9 for (int i = 0; i < n; i++) { 10 const auto it = mp.lower_bound(intervals[i][1]); 11 res[i] = it != mp.end() ? it->second : -1; 12 } 13 14 return res; 15 } 16 };