My java AC solution use Exception


  • -2
    S
    public boolean isNumber(String s){
    	s = s.trim();
    	if(s.endsWith("f")|| s.endsWith("D"))
    		s = s.substring(0,s.length()-1);
    	
    	try{
    		Float.parseFloat(s);
    	}catch(NumberFormatException e){
    		return false;
    	}
    	return true;
    }

  • 0
    O

    I got test case pass if I do

    if(s.endsWith("f")|| s.endsWith("D")){
    return false;
    }

    Or false in case xxxx.xxxxf


  • 0
    W

    what about end with "F" or "d", for example 1.2F


Log in to reply
 

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