#3516

Find Closest Person

newbie · 100 · lc easy +12 · 88.9% accepted · 426 likes · top 99%

Description

Three people stand on a number line at positions x (Person 1), y (Person 2), and z (Person 3). Person 3 stays fixed; Persons 1 and 2 both move toward Person 3 at equal speed.

Return 1 if Person 1 arrives first, 2 if Person 2 arrives first, or 0 if they arrive simultaneously.

Code

1
2
3