Java One-Liner accepted solution (regex)!


  • 0
    P

    I don't think am the first to get it but here it is:

    public class Solution {
        public boolean isNumber(String s) {
             return s.trim().matches("[+-]?(([0-9]*\\.?[0-9]+)|([0-9]+\\.?[0-9]*))([eE][+-]?[0-9]+)?");
        }
    }
    

    BOOM!


Log in to reply
 

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