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

  • 2
    public boolean isNumber(String s) {
            Double x = Double.parseDouble(s); //is this possible?
           }catch(NumberFormatException e){ //no return false
            return false;
            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.