publicclassZYH{ publicintintegerReplacement(int n){ int ans = 0; long m = n; while (m != 1) { if (m % 2 == 0) { m = m / 2; ans++; } elseif (m % 2 != 0) { if (m != 3 && (m + 1) % 4 == 0) { m = m + 1; ans++; } else { m = m - 1; ans++; } } } return ans; }
publicstaticvoidmain(String[] args){ // TODO Auto-generated method stub ZYH s = new ZYH(); int b = 2147483647; int a = s.integerReplacement(b); System.out.print(a);