Cheating solution by using strtold

  • 0
    class Solution {
      bool isNumber(string s) {
        char *end;
        strtold(s.c_str(), &end);
        if (end == s.c_str()) {
          return false;
        for (; isspace(*end); end++);
        return *end == '\0';

    And yes, I intended to break the rules by using libc.

Log in to reply

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