A valid number can be split up into these components (in order):


	A decimal number or an integer.
	(Optional) An 'e' or 'E', followed by an integer.


A decimal number can be split up into these components (in order):


	(Optional) A sign character (either '+' or '-').
	One of the following formats:
	
		One or more digits, followed by a dot '.'.
		One or more digits, followed by a dot '.', followed by one or more digits.
		A dot '.', followed by one or more digits.
	
	


An integer can be split up into these components (in order):


	(Optional) A sign character (either '+' or '-').
	One or more digits.


For example, all the following are valid numbers: ["2", "0089", "-0.1", "+3.14", "4.", "-.9", "2e10", "-90E3", "3e+7", "+6e-1", "53.5e93", "-123.456e789"], while the following are not valid numbers: ["abc", "1a", "1e", "e3", "99e2.5", "--6", "-+3", "95a54e53"].

Given a string s, return true if s is a valid number.

&nbsp;
Example 1:

Input: s = "0"
Output: true


Example 2:

Input: s = "e"
Output: false


Example 3:

Input: s = "."
Output: false


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 20
	s consists of only English letters (both uppercase and lowercase), digits (0-9), plus '+', minus '-', or dot '.'.


class Solution:
    def isNumber(self, s: str) -> bool:
        if s == "inf" or s == "-inf" or s == "+inf" or s == "Infinity" or s == "-Infinity" or s == "+Infinity":
            return False
        try:
            float(s)
        except (Exception):
            return False
        return True
class Solution {
    public boolean isNumber(String s) {
        try{
            int l=s.length();
            if(s.equals("Infinity")||s.equals("-Infinity")||s.equals("+Infinity")||s.charAt(l-1)=='f'||s.charAt(l-1)=='d'||s.charAt(l-1)=='D'||s.charAt(l-1)=='F')
            return false;
            double x=Double.parseDouble(s);
            return true;
        }
        catch(Exception e){
            return false;
        }
        
    }
}
/*
Max Possible combination of characters in the string has followig parts(stages) :
            +/- number . number e/E +/- number
stages: 0 1 2 3 4 5 6 7

Now check each characters at there correct stages or not and increament the stage
as per the character found at ith position.

*/

class Solution {
public:
    bool isNumber(string s){
        char stage = 0;
        for(int i = 0; i<s.size(); ++i){
            if( (s[i] == '+' || s[i] == '-') && (stage == 0 || stage == 5)){ stage++; }
            else if((s[i] == 'e' || s[i] == 'E') && stage > 1 && stage < 5){ stage = 5; }
            else if(s[i] == '.' && stage < 3) {
                //both side of '.' do not have any digit then return false
                if(stage <= 1 && ( i + 1 >= s.size() || !(s[i+1] >= '0' && s[i+1] <= '9')) ) return false;
                stage = 3;
            }else if(s[i] >= '0' && s[i] <= '9'){
                if(!(stage == 2 || stage == 4 || stage == 7) ) stage++;
                if(stage == 1 || stage == 6 ) stage++;
            }else return false;
        }
        if(stage <= 1 || stage == 5 || stage == 6) return false;
        return true;
    }
};
/**
 * @param {string} s
 * @return {boolean}
 */
var isNumber = function(s) {
    const n = s.length;
    const CHAR_CODE_UPPER_E = 'E'.charCodeAt(0);
    const CHAR_CODE_LOWER_E = 'e'.charCodeAt(0);
    const CHAR_CODE_UPPER_A = 'A'.charCodeAt(0);
    const CHAR_CODE_UPPER_Z = 'Z'.charCodeAt(0);
    const CHAR_CODE_LOWER_A = 'a'.charCodeAt(0);
    const CHAR_CODE_LOWER_Z = 'z'.charCodeAt(0);

    let sign = '';
    let decimal = '';
    let exponential = '';
    let exponentialSign = '';
    let num = '';
    for(let i = 0; i < n; i += 1) {
        const char = s[i];
        const charCode = s.charCodeAt(i);

        if(char === '+' || char === '-') {
            if(i === n - 1) return false;
            if(i === 0) {
                sign = char;
                continue;
            }

            if(exponentialSign.length > 0) return false;
            if(!(s[i - 1] === 'e' || s[i - 1] === 'E')) return false;
            exponentialSign = char;
            continue;
        }

        if(char === '.') {
            if(decimal.length > 0) return false;
            if(exponential.length > 0) return false;
            if(num.length === 0 && i === n - 1) return false;

            decimal = char;
            continue;
        }

        if(charCode === CHAR_CODE_UPPER_E || charCode === CHAR_CODE_LOWER_E) {
            if(exponential.length > 0) return false;
            if(i === n - 1) return false;
            if(num.length === 0) return false;

            exponential = char;
            continue;
        }

        if(charCode >= CHAR_CODE_UPPER_A && charCode <= CHAR_CODE_UPPER_Z) {
            return false;
        }

        if(charCode >= CHAR_CODE_LOWER_A && charCode <= CHAR_CODE_LOWER_Z) {
            return false;
        }

        num += char;
    }

    return true;
};
Valid Number