JS19. 判断斐波那契数组
描述
请补全JavaScript代码,要求以Boolean的形式返回参数数组是否为斐波那契数列。在数学上,斐波那契数列以如下方法定义:F(0)=0,F(1)=1, F(n)=F(n - 1)+F(n - 2)(n ≥ 2,n ∈ N)HTML/CSS/JavaScript 解法, 执行用时: 1714ms, 内存消耗: 77772KB, 提交时间: 2022-02-09
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _isFibonacci = array => {\n if(array.length<3){\n return false\n }\n else{\n for(let i=0;i<array.length;i++){\n if(i>1&&array[i]!=array[i-1]+array[i-2]){\n return false\n }\n }\n }\n return true\n \n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1719ms, 内存消耗: 77788KB, 提交时间: 2022-02-09
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _isFibonacci = array => {\n // 补全代码\n if(array.length<3){\n return false;\n }\n for(i=0;i<array.length;i++){\n if(i>1 && array[i]!=array[i-1]+array[i-2]){\n return false;\n }\n }\n return true;\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1745ms, 内存消耗: 77884KB, 提交时间: 2022-01-22
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _isFibonacci = array => {\n // 补全代码\n if(array.length<3) return false\n for(let i = 2;i<array.length;i++){\n if(array[i-2]+array[i-1] != array[i]){\n return false\n }\n }\n return true\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1750ms, 内存消耗: 77900KB, 提交时间: 2021-12-07
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _isFibonacci = array => {\n // 补全代码\n if(array.length==0) return false\n \n if(array.length==1){\n if(array[0]==0){\n return true\n }else{ \n return false\n }\n }\n if(array.length==2){\n if(array[0]==0&&array[1]==1){\n return true\n }else{ \n return false\n }\n }\n if(array.length==3){\n if(array[0]==0&&array[1]==1&&array[2]==1){\n return true\n }else{ \n return false\n }\n }\n\n for(var i=3;i<array.length;i++){\n if(array[i]==(array[i-1]+array[i-2])){\n continue;\n }else{\n return false \n }\n }\n return true\n }\n </script>\n </body>\n</html>","libs":[]}
HTML/CSS/JavaScript 解法, 执行用时: 1751ms, 内存消耗: 77772KB, 提交时间: 2022-01-05
{"css":"","js":"","html":"<!DOCTYPE html>\n<html>\n <head>\n <meta charset=utf-8>\n </head>\n <body>\n \t\n <script type=\"text/javascript\">\n const _isFibonacci = array => {\n // 补全代码\n if(array.length<3) return false;\n for(let i = 2;i<array.length;i++){\n if(array[i] = array[i-1]+array[i-2]) continue\n return false\n }\n return true\n }\n </script>\n </body>\n</html>","libs":[]}