Java Regex for Valid Number

  • 0
    public class Solution {
    public boolean isNumber(String s) {
    if(s.matches("(\\s?\\-?\\+?(\\d+)?(\\.|e)?(\\d+)?\\s?)") && s!="e")
    	return true;
    	else if(s=="e") return false;
    	else return false;

    can any one take a look at my code and see what's missing from it? For me it works with any test case, however when I run it here, it has some problem validating e.

  • 0

    You can't use != and == to compare Strings in Java. Your code should say !s.equals("e") and s.equals("e") for those comparisons.

Log in to reply

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