【leetcode】第65题 Valid Number 这道题用JS代码超级简单=-=

xiaoxiao2021-02-27  148

【题目】

Validate if a given string is numeric.

Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true

Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

【解析】

判断一个字符串是否是数字类型,是返回true,否返回false。一看到这题我就想到了JS超级简单,JAVA的解法下次补上。。。

【代码】

var isNumber = function(s) { if(s==" ") return false; var bool=Number(s); if(bool==0) return true; else return Boolean(bool); };

转载请注明原文地址: https://www.6miu.com/read-15345.html

最新回复(0)