列表

详情


JS30. 回文字符串

描述

请补全JavaScript代码,要求以boolean的形式返回参数字符串是否为回文字符串。

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 1690ms, 内存消耗: 77804KB, 提交时间: 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 _isPalindrome = string => {\n                // 补全代码\n                let oldarr=string.split('').join('')\n                let newarr=string.split('').reverse().join('')\n                if(oldarr=newarr){\n                    return true\n                }\n                else\n                    {\n                        return false\n                    }\n                \n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1751ms, 内存消耗: 77900KB, 提交时间: 2022-01-23

{"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 _isPalindrome = string => {\n                // 补全代码\n                if(string.length==1){\n                    return true;\n                }\n                else if(string.length==2 && string.charAt(0)==string.charAt(1)){\n                    return true;\n                }\n                else{\n                    return string.charAt(0)==string.charAt(string.length-1) && _isPalindrome(string.substring(1,string.length-1));\n                }\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1753ms, 内存消耗: 77892KB, 提交时间: 2021-12-27

{"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 _isPalindrome = string => {\n                // 补全代码\n                var huiwen = Math.floor(string.length/2)\n                for(let i=0;i<huiwen;i++){\n                    if(string[i]!=string[string.length-i-1]){\n                        return false;\n                    }\n                }\n                return true\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1753ms, 内存消耗: 77900KB, 提交时间: 2022-01-06

{"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 _isPalindrome = string => {\n                // 补全代码\n                  return string === string.split('').reverse().join('')\n            }\n        </script>\n    </body>\n</html>","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 1753ms, 内存消耗: 77900KB, 提交时间: 2021-12-06

{"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 _isPalindrome = string => {\n                // 补全代码\n                return string.split('').reverse().join('')==string\n            }\n        </script>\n    </body>\n</html>","libs":[]}

上一题