Javascript solution using regex


  • 0
    R
    var isNumber = function(s) {
        var regex = /^([-]?[+]?[\d]*[.]?[\d]*)?(([-]?[+]?[\d]*[\d])+[.]?[e]([-]?[+]?[\d]+)+)?$/;
        var temp = s.trim();
        return !(temp === '-+') &&  !(temp === '+-') && !(temp === '+.') && !(temp === '-.') 
    && !(temp === '.') && !(temp === 'e')  && !!temp && !!temp.match(regex);
    }

Log in to reply
 

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