Java solution with regex

  • 0

    Code to validate by regex if given string is a numeric

    class Solution {
        public boolean isNumber(String s) {
            if (s == null || s.trim().length() == 0) return false;
            return s.trim().matches("^(-|\\+)?\\d*(\\d+|\\d+\\.|\\.\\d+)\\d*(e(\\+|-)?\\d+)?$");

Log in to reply

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