Published on

Leetcode - 613. Shortest Distance in a Line

Authors
  • avatar
    Name
    Indo Yoon
    Twitter
Table of Contents

문제

[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.

LeetCode

](https://leetcode.com/problems/shortest-distance-in-a-line/)

정답

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