397. 整数替换
1 class Solution 2 { 3 public: 4 int integerReplacement(int n) 5 { 6 return DFS(n); 7 } 8 9 long long DFS(long long n) 10 { 11 if(n == 1) return 0; 12 if(n & 1) return min(DFS(n + 1),DFS(n - 1)) + 1; 13 else return DFS(n/2) + 1; 14 } 15 };
Mamba never out

浙公网安备 33010602011771号