Xiaoli's javascript solution for leetcode