The problem comes from Leetcode 065:
Valid number
If you use regular expressions to write a floating-point resolution, it's probably:
[+-]? ([0-9]+\.?) | (\. [0-9])) [0-9]* ([ee][+-]?[ 0-9]+)?
I myself use dot to draw a state machine out:
If you write code to simulate the state machine, you can split the "EE" into two parts of the processing; the front part of "EE" can also be split into "." Before and after two parts (if a bit) to write.
This problem on the Leetcode difficulty for hard, you can see this small details, more able to test the basic skills.
------------------
Due to the word limit, attach my words this state machine uses the source code:
1 digraph {2 Graph [fontname = "Microsoft Yahei", fontsize=16 ranksep=1.0 splines=1 overlap=false size= "+," compound=true]
3 Edge [fontname = "Microsoft Yahei", fontsize=16]4 node [fontname = "Microsoft Yahei", fontsize=16 weight=2 rank=same width=1 RANKDIR=LR]5 6 p0[label= "Start"]7 p2[label= "Initial-check"]8 p4[label= "Dot-first"]9 p5[label= "AFTER-E"]Ten p6[label= "After-e-mark"] One p7[label= "Almost-done"] A p8[label= "End"] - p9[label= "Sign-mark"] - pa[label= "After-dot"] the - - P0-P9[label= "[+-]"] - P0, p9[label= "blank-string"] + - P9, P4[label= "". + A p9-P2[label= "[0-9]"] at - P2-p2[label= "[0-9]"] - P2, pa[label= "". - P2, pa[label= "blank-string"] - P4-Pa[label= "[0-9]"] - PA-and Pa[label= "[0-9]"] in PA-p8[label= "$"] - PA-P5[label= "[Ee]"] to P5-p6[label= "[+-]"] + P5, p6[label= "blank-string"] - P6-P7[label= "[0-9]"] the P7-P7[label= "[0-9]"] * P7, p8[label= "$"] $}
State machine for handling floating-point numbers