leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0789.cpp (428B)
0 class Solution { 1 int distance(const vector<int> &a, const vector<int> &b) const { 2 return abs(a[0] - b[0]) + abs(a[1] - b[1]); 3 } 4 5 public: 6 bool escapeGhosts(const vector<vector<int>> &ghosts, const vector<int> &target) const { 7 const int pm = distance(target, {0, 0}); 8 for (const auto &ghost : ghosts) 9 if (pm >= distance(target, ghost)) return false; 10 return true; 11 } 12 };