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.
Update (2015-02⑴0):
The signature of the C++ function had been updated. If you still see your function
signature accepts a const char * argument, please click the reload button to
reset your code definition.
判断数字的合法性
刚开始是把它作为1道细节较多的摹拟题做的,通过后去discuss看了1下,果然有优美的解答!
用有限状态机DFA解决,将每位看成1种状态转移条件,每次读取的1位,就根据转移矩阵进行状态转移,若转移到不合法的状态则返回false。
思路简单优美,不用斟酌过剩的细节问题,刷了这么多leetcode,这题真的眼前1亮!
具体的状态说明可以看这篇博客
上一篇 sql server 2012版 学习笔记(基础版)
下一篇 编辑器代码高亮测试