leetcode 054-055; 045 improved