思路:差分数组
class Solution { public: int numberOfPoints(vector<vector<int>>& nums) { int diff[102] = {}; for(auto p : nums)//差分 { diff[p[0]] ++ ; diff[p[1] + 1] -- ; } int res = 0, s = 0; for(int i : diff)//前缀和还原 { s += i; res += s > 0; } return res; } };
2849. 判断能否在给定时间到达单元格 - 力扣(LeetCode)
思路:可惜我没有超级大脑
class Solution { public: bool isReachableAtTime(int sx, int sy, int fx, int fy, int t) { if(sx == fx && sy == fy) return t != 1; return max(abs(sx - fx), abs(sy - fy)) <= t; } };