LeetCode solution By Li Yiji. Maybe not best, just a reference for others.