DENA面试总结
有m瓶可乐,n瓶空瓶可换取1瓶可乐,不可借用空瓶,问总共可以喝到多少瓶可乐?
有m瓶可乐,n瓶空瓶可换取1瓶可乐,不可借用空瓶,问总共可以喝到多少瓶可乐?
int culTotalBottle(int m, int n)
{
int total = m;
int empty = m;
while(empty >= n)
{
total += empty / n;
empty = empty / n + empty % n;
}
return total;
}
int culTotalBottleRecusive(int empty, int n)
{
if(empty < n)
return 0;
return empty / n + culTotalBottleRecusive(empty / n + empty % n, n);
}
int culTotalBottle2(int m, int n)
{
return m + culTotalBottleRecusive(m, n);
}
Read full article from DENA面试总结