Leetcode solutions with explanation