Posted on

Description

Submission

class Solution {
    inline int manhanttanDistance(int x1, int y1, int x2, int y2) {
        return abs(x1 - x2) + abs(y1 - y2);
    }
public:
    bool escapeGhosts(vector<vector<int>>& ghosts, vector<int>& target) {
        int distance = manhanttanDistance(target[0], target[1], 0, 0);

        for(auto ghost: ghosts) {
            int d = manhanttanDistance(ghost[0], ghost[1], target[0], target[1]);
            if(d <= distance) return false;
        }

        return true;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *