Coding Test

Leetcode - 613. Shortest Distance in a Line

Indo Yoon

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

정답

LAG 를 써서 1줄 차이를 구한 다음 거리를 계산했다.

SELECT MIN(dist) AS shortest
FROM (
    SELECT ABS(x - LAG(x, 1) OVER (ORDER BY x)) as dist
    FROM Point
    ORDER BY dist
) AS Temp
WHERE dist IS NOT null