leetcode 018 improved