百度第二题 小度部队,递归法

public class 小度的部队 {

static int shu = 0;

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n =sc.nextInt(),k=sc.nextInt();

System.out.println(returnNum(n,k));

}

public static int returnNum(int m,int n){

int i =1;

boolean flag = false;

while (i<=m){

if((i+n)==(m-i)){

flag = true;

break;

}else {

i++;

}

}

if(flag){

returnNum((m-i),n);

returnNum(i,n);

}else {

shu++;

}

return shu;

}

}

#笔试题目##百度#
全部评论

相关推荐

程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务