Clear solution with Double.valueOf


  • 0
    S
    import java.util.*;
    public class Solution {
        public boolean isNumber(String s) {
            try{
                char c = s.charAt(s.length()-1);
                //排除Double类对特殊的末尾字符为F(f)或D(d)的处理
                if(c == 'F' || c == 'f' ||c == 'd' ||c == 'D' )
                    return false;
                Double value = Double.valueOf(s);
                return true;
            }catch(NumberFormatException e){
                //NumberFormatException如果字符串不包含一个可分裂的数字
                return false;
            }
        }
    }
    

Log in to reply
 

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