Share my concise C solution, 8 ms


  • 0
    H
    int readdigit(char** s, bool allowSign) {
        int count = 0;
        if (allowSign) {
            if ('+' == **s || '-' == **s) {
                ++*s;
            }
        }
        while ('0' <= **s && **s <= '9') {
            ++*s;
            count++;
        }
        return count;
    }
    void skipblank(char** s) {
        while (' ' == **s) {
            ++*s;
        }
    }
    bool isNumber(char* s) {
        int count = 0, fcount = 0;
        skipblank(&s);
        count = readdigit(&s, true);
        if ('.' == *s) {
            s++;
            fcount = readdigit(&s, false);
        }
        if (('e' == *s || 'E' == *s) && (count + fcount)) {
            s++;
            if (!(count = readdigit(&s, true))) {
                return false;
            }
        }
        skipblank(&s);
        return (count + fcount) && !*s;
    }

Log in to reply
 

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