列表

详情


FED75. 判断是否包含数字

描述

给定字符串 str,检查其是否包含数字,包含返回 true,否则返回 false

示例1

输入:

'abc123'

输出:

true

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 857ms, 内存消耗: 77772KB, 提交时间: 2021-05-23

{"css":"","js":"function containsNumber(str) {\n    for(let i= 0; i< str.length; i++) {\n        if(!isNaN(Number(str[i]))) return true\n    }\n    return false\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 857ms, 内存消耗: 77772KB, 提交时间: 2021-04-04

{"css":"","js":"function containsNumber(str) {\n    const reg = /([0-9])/\n    return reg.test(str)\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 857ms, 内存消耗: 77772KB, 提交时间: 2021-03-22

{"css":"","js":"var str = 'abc123'\nfunction containsNumber(str) {\n   for(let i=0;i<10;i++){\n       if(str.indexOf(i) != -1 ){\n           return true\n       }\n   }\n    return false\n}\ncontainsNumber(str)","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 858ms, 内存消耗: 77852KB, 提交时间: 2021-03-28

{"css":"","js":"function containsNumber(str) {\n    return /\\d+/g.test(str)\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 860ms, 内存消耗: 77772KB, 提交时间: 2020-11-22

{"css":"","js":"function containsNumber(str) {\n      for (var i = 0; i < str.length; i++) {\n        if (!isNaN(parseInt(str[i]))) {\n          return true;\n        }\n      }\n      return false;\n    }","html":"","libs":[]}

上一题