You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EASY/src/easy/StringToInteger.java
+57-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,6 @@
1
1
packageeasy;
2
+
3
+
importjava.util.HashSet;
2
4
/**8. String to Integer (atoi) QuestionEditorial Solution My Submissions
3
5
Total Accepted: 115114
4
6
Total Submissions: 839893
@@ -8,6 +10,7 @@
8
10
Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.
9
11
10
12
Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front.*/
13
+
importjava.util.Set;
11
14
12
15
/**Requirements for atoi:
13
16
The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value.
@@ -28,6 +31,59 @@ public int myAtoi(String str) {
28
31
//case 4: there're many leading whitespace characters which we'll have to ignore
29
32
30
33
//case 5: when finding the first non-whitespace character, it could possibly be a '+' or '-' sign, after that, we parse all the consecutive numbers
31
-
return0;
34
+
35
+
str = str.trim();//cut off its leading and trailing whitespace characters
0 commit comments