😕题目描述
😔分析
因为所有节点都是从(sx,sy)到(sx+sy,sy)或(sx,sx+sy)则所有的值都是大于0的。(tx,ty)一定是从(tx-ty,ty)或(tx,ty-tx)转换过来的,但是如果
tx==ty则会出现0位置,所以此时不满足条件;tx>ty则ty-tx<0,此时(tx,ty-tx)不满足条件;ty>tx则tx-ty<0,此时(tx-ty,ty)不满足条件;
因此从(tx,ty)进行逆向转换,最终会得到一下四种状态:
sx==tx&&sy==ty:此时满足情况;sx==tx&&sy!=ty:此时如果(ty-sy)%tx==0满足情况;sx!=tx&&sy==ty:此时如果(tx-sx)%ty==0满足情况;sx!=tx&&sy!=ty:不满足情况。😏答案
```go func reachingPoints(sx int, sy int, tx int, ty int) bool { for tx > sx && ty > sy {
} if tx == sx && ty == sy {if tx == ty {return false} else {if tx > ty {tx = tx - ty} else {ty = ty - tx}}
} else {return true
} }if tx == sx && ty > sy {if (ty-sy)%tx == 0 {return true} else {return false}} else {if ty == sy && tx > sx {if (tx-sx)%ty == 0 {return true} else {return false}} else {return false}}
```
