Skip to main content
  1. LeetCode/

LeetCode 3516: Find Closest Person

·1 min· ·
LeetCode Blog Weekly Easy
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents
LeetCode Weekly Contest 445 - This article is part of a series.
Part 1: This Article

Meta Data
#

Difficulty: easy First Attempt: 2025-04-13

  • Total time: 02:00.00

Intuition
#

Just use brute-force to calculate the distance from x to z and from y to z, then compare the distances and return the result.

Approach
#

class Solution:
    def findClosest(self, x: int, y: int, z: int) -> int:
        distance_x_z = abs(z-x)
        distance_y_z = abs(z-y)
        
        if distance_x_z>distance_y_z:
            return 2
        elif distance_x_z<distance_y_z:
            return 1
        return 0

Findings
#

NA

Encountered Problems
#

NA

LeetCode Weekly Contest 445 - This article is part of a series.
Part 1: This Article

Related

LeetCode 3517: Smallest Palindromic Rearrangement I
·1 min
LeetCode Blog Weekly Medium
LeetCode Problem Solving
LeetCode 3512: Minimum Operations to Make Array Sum Divisible by K
·1 min
LeetCode Blog Bi-Weekly Easy
LeetCode Problem Solving
LeetCode 2843: Count Symmetric Integers
·1 min
LeetCode Blog Daily Easy
LeetCode Problem Solving
LeetCode 617: Merge Two Binary Trees
·2 mins
LeetCode Blog Daily Easy
LeetCode Problem Solving
LeetCode 1922: Count Good Numbers
·2 mins
LeetCode Blog Daily Medium
LeetCode Problem Solving
LeetCode 556: Next Greater Element III
·1 min
LeetCode Blog Medium
LeetCode Problem Solving