LeetCode: Valid Number

LeetCode Valid Number Problem Description:

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.

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.

Finite State Machine For Valid Number

Written on May 1, 2013