Solution and my reference to Leetcode