Solve two problems in leetcode