Math 3516. Find Closest Person ¶ Time: $O(1)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9 10class Solution { public: int findClosest(int x, int y, int z) { const int xz = abs(x - z); const int yz = abs(y - z); if (xz == yz) return 0; return xz < yz ? 1 : 2; } }; 1 2 3 4 5 6 7 8 9class Solution { public int findClosest(int x, int y, int z) { final int xz = Math.abs(x - z); final int yz = Math.abs(y - z); if (xz == yz) return 0; return xz < yz ? 1 : 2; } } 1 2 3 4 5 6 7class Solution: def findClosest(self, x: int, y: int, z: int) -> int: xz = abs(x - z) yz = abs(y - z) if xz == yz: return 0 return 1 if xz < yz else 2 Was this page helpful? Thanks for your feedback! Thanks for your feedback! Help us improve this page by using our feedback form.