User Regular Expression to solve the question


  • 2
    T
        final String  REGEX_INTEGER="^-?\\+?\\d+$";
        final String  REGEX_DECIMAL="^-?\\+?\\d+\\.\\d{0,}$|^-?\\+?\\d{0,}\\.\\d+$";
        final String  REGEX_SCIENCE="^-?\\+?\\d+\\.\\d{0,}([Ee]{1}(-?\\+?\\d+))$|" +
                "^-?\\+?\\d{0,}\\.\\d+([Ee]{1}(-?\\+?\\d+))$|" +
                "^-?\\+?\\d+([Ee]{1}(-?\\+?\\d+))$";
        String str = s.trim();
        return str.matches(REGEX_DECIMAL)||str.matches(REGEX_INTEGER)||str.matches(REGEX_SCIENCE);

Log in to reply
 

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