leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

3015.cpp (420B)


0 class Solution { 1 public: 2 vector<int> countOfPairs(int n, int x, int y) const { 3 vector<int> res(n); 4 5 x--, y--; 6 if (x > y) swap(x, y); 7 for (int i = 0; i < n - 1; i++) { 8 for (int j = i + 1; j < n; j++) { 9 const int dist = min(abs(i - j), abs(i - x) + abs(j - y) + 1); 10 res[dist - 1] += 2; 11 } 12 } 13 14 return res; 15 } 16 };