My tricky js solutions, and some examples for test


  • 0

    Notice: '004', '0.1', '.2', '3.', '-1.', '46.e3', .3e3, ' 005047e+6' are valid numbers.
    I think this should add into examples of the question.

    Here is my js solutions:

    const isNumber = (s) => {
        // notice: '004', '.2', '3.', '-1.', '46.e3', .3e3, ' 005047e+6' are valid numbers
        // return /^\s*[-+]?((\d+\.?)|(\d*\.\d+))(e[-+]?\d+)?\s*$/i.test(s);
        return !isNaN(s) && !!s.replace(/\s/g,'');
    };
    

Log in to reply
 

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