Integer Replacement Leetcode Javascript