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版 學習筆記(基礎版)
下一篇 編輯器代碼高亮測試