You are viewing a single comment's thread. Return to all comments →
C++
int beautifulTriplets(int d, vector<int> arr) { size_t n = arr.size(), i = 0, nbt = 0; vector<size_t> bd(n); for(i = 0; i < n; i++) { auto lb = lower_bound(arr.begin(), arr.end(), arr[i]+d); if(lb != arr.end() && (*lb) == arr[i]+d) bd[i] = lb - arr.begin(); } for(i = 0; i < n; i++) if(bd[i] && bd[bd[i]]) ++nbt; return nbt; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Triplets
You are viewing a single comment's thread. Return to all comments →
C++