- (int)power:(int)a withb:(int) b
{
if (b == 1) return a;
int temp = [self power:a withb:b/2];
if ((b&1) != 0) {
return a * temp * temp;
}else{
return temp * temp;
}
}
- (int)power:(int)a withb:(int) b
{
if (b == 1) return a;
int temp = [self power:a withb:b/2];
if ((b&1) != 0) {
return a * temp * temp;
}else{
return temp * temp;
}
}
本文标题:递归还是非常有用,自己实现下“求n的m次方
本文链接:https://www.haomeiwen.com/subject/evrzjctx.html
网友评论