mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-24 00:57:05 +08:00
Update
This commit is contained in:
@ -54,9 +54,9 @@ int function2(int x, int n) {
|
||||
|
||||
```CPP
|
||||
int function3(int x, int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (n == 0) return 1;
|
||||
if (n == 1) return x;
|
||||
|
||||
if (n % 2 == 1) {
|
||||
return function3(x, n / 2) * function3(x, n / 2)*x;
|
||||
}
|
||||
@ -93,9 +93,8 @@ int function3(int x, int n) {
|
||||
|
||||
```CPP
|
||||
int function4(int x, int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (n == 0) return 1;
|
||||
if (n == 1) return x;
|
||||
int t = function4(x, n / 2);// 这里相对于function3,是把这个递归操作抽取出来
|
||||
if (n % 2 == 1) {
|
||||
return t * t * x;
|
||||
@ -124,9 +123,8 @@ int function4(int x, int n) {
|
||||
|
||||
```CPP
|
||||
int function3(int x, int n) {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
if (n == 0) return 1;
|
||||
if (n == 1) return x;
|
||||
if (n % 2 == 1) {
|
||||
return function3(x, n / 2) * function3(x, n / 2)*x;
|
||||
}
|
||||
|
Reference in New Issue
Block a user