最优惠的手机网站建设,做网站购买服务器,桥梁建设工程网站,网站开发方倍工作室题目#xff1a; 题解#xff1a;
class Solution:def integerReplacement(self, n: int) - int:ans 0while n ! 1:if n % 2 0:ans 1n // 2elif n % 4 1:ans 2n // 2else:if n 3:ans 2n 1else:ans 2n n // 2 1return ans题目 题解
class Solution:def integerReplacement(self, n: int) - int:ans 0while n ! 1:if n % 2 0:ans 1n // 2elif n % 4 1:ans 2n // 2else:if n 3:ans 2n 1else:ans 2n n // 2 1return ans