I might not get the whole point of this question, but I would just try to parse it like this


  • 0
    H
    public class Solution {
        public boolean isNumber(String s) {
            int tries = 2;
            try {
                int i = Integer.valueOf(s);
            } catch(Exception e) {
                tries--;
            }
            
            try {
                double d = Double.valueOf(s);
            } catch(Exception e) {
                tries--;
            }
            
            return (tries > 0? true : false);
        }
    }

Log in to reply
 

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