Skip to content

Commit ab62391

Browse files
authored
Create 8. String to Integer (atoi)
1 parent 1b3b375 commit ab62391

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

8. String to Integer (atoi)

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public int myAtoi(String str) {
3+
int l=str.length();
4+
int sign = 0;
5+
int result = 0;
6+
int index = 0;
7+
8+
9+
if(l==0) return 0;
10+
if(str.charAt(0)=='+'){
11+
sign = 1;
12+
index++;
13+
}else if(str.charAt(0)=='-'){
14+
sign = -1;
15+
index++;
16+
}else{
17+
sign = 1;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)