simple in java with Double class


  • 0
    S
       public boolean isNumber(String s) {
          if (s == null || s.trim().length() == 0){
             return false;
          }
          s = s.trim();
          char last = s.charAt(s.length()-1);
          if (last == '.' || (last > 57 || last < 48)){
             return false;
          }
          try{
             Double db = Double.valueOf(s);
          }catch (Exception e){
             return false;
          }
          return true;
      }

Log in to reply
 

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