[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/feiyunwill/LeetCode-Solutions/master/MySQL/exchange-seats.sql [Back]  [Original]

# Time:  O(nlogn)
# Space: O(n)

SELECT
    s1.id, COALESCE(s2.student, s1.student) AS student
FROM
    seat s1
        LEFT JOIN
    seat s2 ON ((s1.id + 1) ^ 1) - 1 = s2.id
ORDER BY s1.id;


Web Proxy Viewer  |  New URL  |  Original Page