Last active
August 29, 2015 14:27
-
-
Save DmytroMitin/8e1fe8aa0a7406c508ae to your computer and use it in GitHub Desktop.
http://ec2-52-27-141-35.us-west-2.compute.amazonaws.com/problem/55b5147a56481b5f1661d8ba https://leetcode.com/problems/valid-number/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Doubles { | |
public Double parse(String s) { | |
if (isNumber(s)) { | |
return Double.valueOf(s); | |
} else { | |
return null; | |
} | |
} | |
public boolean isNumber(String s) { | |
try { | |
Double.valueOf(s); | |
if (s.charAt(s.length() - 1) == 'f' || s.charAt(s.length() - 1) == 'F' || s.charAt(s.length() - 1) == 'd' || s.charAt(s.length() - 1) == 'D') { | |
return false; | |
} | |
return true; | |
} catch (NumberFormatException e) { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment