The most elegant solution of LeetCode.