Problem: 8049. Determine whether the cell can be reached at a given time
Article directory
Ideas
Use mathematical thinking to write this question
the complexity
- time complexity:
Add time complexity, example: O ( 1 ) O(1)O(1)
Code
class Solution
{
public:
bool isReachableAtTime(int sx, int sy, int fx, int fy, int t)
{
if(sx == fx && sy == fy)
{
if(t == 1) return false;
}
int heng = abs(sx - fx);
int shu = abs(fy - sy);
int max_ans = heng + shu;
int min_ans = max(heng,shu);
if(t >= min_ans) return true;
else return false;
}
};