LeetCode: Valid Number
LeetCode Valid Number Problem Description:
Validate if a given string is numeric.
" 0.1 " =>
"1 a" =>
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
LeetCode Valid Number Solution and Precautions:
This problem description is indeed fuzzy: several special cases are
// 3e3.1 is false
// -1. is true
// +.1 is true
// 1.e3 is true
The solution is to build a DFA to process the string, the following is my DFA (please forgive me for the ugly drawing >_<), and at first I think come up with a regular expression first, then translate it into DFA would be easier for bug free code, but later on I found it more complicated, so one better just build the DFA directly.