AC leetcode problem