leetcode refactoring