S2 初级场 B题

两边之和大于第三边,最短边不小于1,显然是斐波那契数列
```java
import java.util.*;
public class Solution {
/**
*
* @param a long长整型 木棒的长度
* @return
int整型
*/
public int stick (long a) {
// write code here
long ans = 0;
long f1 = 0, f2 = 1;
while (a >= f2){
ans++;
a -= f2;
long temp = f1 + f2;
f1 = f2;
f2 = temp;
}
return (int)ans;
}
}

```
#笔试题目#
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务