题解 | #判断斐波那契数组#

判断斐波那契数组

https://www.nowcoder.com/practice/9df2a366eb25495caff41612bd0ffca6

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8>
    </head>
    <body>
    	
        <script type="text/javascript">
            const _isFibonacci = array => {
              // 补全代码
              let res = false;
              let resNum = 0;
              for(let i=0; i<array.length; i++) {
                let resNum = (1/Math.sqrt(5)) * (Math.pow(((1+Math.sqrt(5))/2), i) - Math.pow(((1-Math.sqrt(5))/2), i));
                if (array[i] === parseInt(resNum)) {
                  res = true;
                } else {
                  res = false;
                }
              }
              return res;
            }
        </script>
    </body>
</html>
数学方法试一试
#牛客专项练习#
全部评论

相关推荐

04-25 18:13
五邑大学 Java
无面如何呢:用心包装一下自己的实习
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务