Created
January 1, 2017 19:27
-
-
Save iamutkarshtiwari/1ebebf9d40eaf8c02284cfbb013b30a2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /*You are required to complete this method */ | |
| class GfG | |
| { | |
| int atoi(String str) | |
| { | |
| int number = 0; | |
| if (str.length() == 0) | |
| return -1; | |
| for (int i = 0; i< str.length() ; i++ ) { | |
| int c = str.charAt(i); | |
| if ( !(c >= 48 && c<= 57)) { | |
| return -1; | |
| } else { | |
| number = (c-48)*(Math.pow(10, (str.length() - 1 - i ))) + number; | |
| } | |
| } | |
| return number; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment