397. Integer Replacement (Medium)