part of code in Leetcode