This is part of my solutions for leetcode