final changes- code accepted at leetcode