leetcode

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

0789.cpp (428B)


      1 class Solution {
      2     int distance(const vector<int> &a, const vector<int> &b) const {
      3         return abs(a[0] - b[0]) + abs(a[1] - b[1]);
      4     }
      5 
      6   public:
      7     bool escapeGhosts(const vector<vector<int>> &ghosts, const vector<int> &target) const {
      8         const int pm = distance(target, {0, 0});
      9         for (const auto &ghost : ghosts)
     10             if (pm >= distance(target, ghost)) return false;
     11         return true;
     12     }
     13 };