Integer Replacement Leetcode Javascript Solution