I play a trick, use java built-in parser


  • 0
    F
    public boolean isNumber(String s) {
        s = s.trim();
        try {
            Double.parseDouble(s);
        } catch (NumberFormatException e) {
            return false;
        }
        char ch = Character.toLowerCase(s.charAt(s.length() - 1));
        return !(ch == 'f' || ch == 'd');
    }

Log in to reply
 

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