It shows 3. is true, but its wrong i guess ??????


  • 0
    A
    public class Solution {
    public boolean isNumber(String s) {
        s= s.replaceAll(" ","");
       int length = s.length();
       boolean intval = false;
       boolean eval = false;
       boolean dotval = false;
       boolean answer = true;
       int i = 0;
       while(answer && i<length){
            if(s.charAt(i)=='0' || s.charAt(i)=='1' || s.charAt(i)=='2'|| s.charAt(i)=='3'|| s.charAt(i)=='4'|| s.charAt(i)=='5'|| s.charAt(i)=='6'|| s.charAt(i)=='7'|| s.charAt(i)=='8'|| s.charAt(i)=='9'){
                i= i+1;
                intval = true;
            }
            else if(s.charAt(i)=='.'){
                if(dotval){
                    return false;
                  }
                else{
                dotval = true;
                intval=false;
                i++;
                }
    
            }
            else if(s.charAt(i)=='e'){
                if(eval)
                    return false;
                else{
                  eval = true;
                  intval = false;
                }
    
                if(intval || (dotval&&intval)){
                  i++;
                }
                else
                    return false;
            }
            else{
              return false;
            }
       }
       return intval;
    }
    

    }


  • 0
    A

    it is valid,
    you can print out it


Log in to reply
 

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