0436.cpp (468B)
1 class Solution { 2 public: 3 vector<int> findRightInterval(const vector<vector<int>> &intervals) const { 4 const int n = size(intervals); 5 vector<int> res(n); 6 map<int, int> mp; 7 8 for (int i = 0; i < n; i++) 9 mp[intervals[i][0]] = i; 10 for (int i = 0; i < n; i++) { 11 const auto it = mp.lower_bound(intervals[i][1]); 12 res[i] = it != mp.end() ? it->second : -1; 13 } 14 15 return res; 16 } 17 };