Killed it with one RegEx expression


  • 0
    N
    import java.util.regex.*;
    
    public class Solution {
        public boolean isNumber(String s) {
            s = s.trim();
            if(Pattern.matches("([-+])?((\\d+[.]\\d*)|(\\d*[.]\\d+)|(\\d+))([e]([-+])?\\d+)?",s)) {
                return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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