The easiest Java solution ever with try catch block 7 lines of code.


  • 2
    E
    public boolean isNumber(String s) {
        try{
            Double x = Double.parseDouble(s); //is this possible?
           }catch(NumberFormatException e){ //no return false
            return false;
           }finally{
            if (s.matches(".*[a-dA-D].*") || s.matches(".*[f-zF-Z].*")) { 
                    return false; //maybe check if it does contain a character other than e
               }
        }  
      return true;
    }

Log in to reply
 

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