LOL, hard to understand but fast, 8ms


  • 2
    0
    string t [] = {
        "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "100000000003032044444444440000000000000000000000000000000000000000000000000000000000000000000000", 
        "000000000000000066666666660000000000000000000000000000000000000000000000000000000000000000000000", 
        "000000000000002044444444440000000000000000000000000000000000000000000000000000000000000000000000", 
        ":00000000000005044444444440000000000070000000000000000000000000000000700000000000000000000000001", 
        ":00000000000000066666666660000000000070000000000000000000000000000000700000000000000000000000001", 
        ":00000000000000066666666660000000000070000000000000000000000000000000700000000000000000000000001", 
        "000000000008080099999999990000000000000000000000000000000000000000000000000000000000000000000000", 
        "000000000000000099999999990000000000000000000000000000000000000000000000000000000000000000000000", 
        ":00000000000000099999999990000000000000000000000000000000000000000000000000000000000000000000001", 
        ":00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"  
    };
    
    class Solution {
    public:
        bool isNumber(string s) {
            int pos = 1;
            for (char c : s) {
                pos = t[pos][c - ' '] - '0';
                if (pos == 0) return false;
            }
            return t[pos][95] - '0';
        }
    };

  • 0
    H

    Not that hard. It's just a state machine.


  • 0

    You can't write this in a real interview...cuz you have no time to count zeros.....


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.