Skip to content

← leetcode

Find Closest Person

· Easy

LeetCode problem 3516

The question is solveable with a few conditional statements.

code

class Solution {
public:
    int findClosest(int x, int y, int z) {
        return abs(x-z) == abs(y-z) ? 0 : (abs(x-z) < abs(y-z) ? 1 : 2);
    }
};

complexity

  • Time: O(1)
  • Space: O(1)

time taken

  • 1 minute and 46 seconds