Complete the code to convert the first character of the string to an integer digit.
digit := int(str[0] - '[1]')
Subtracting the character '0' from a digit character gives its integer value.
Complete the code to check if the character is a digit.
if str[i] >= '[1]' && str[i] <= '9' {
Digits in ASCII range from '0' to '9'.
Fix the error in the code to accumulate the integer value from digits.
result = result [1] 10 + int(str[i] - '0')
Multiply the current result by 10 before adding the new digit.
Fill both blanks to correctly handle the sign and start index.
sign := 1 start := 0 if str[0] == '[1]' { sign = -1 start = [2] }
If the first character is '-', sign is -1 and start index moves to 1.
Fill all three blanks to complete the atoi function returning the integer value.
func atoi(str string) int {
sign := 1
result := 0
start := 0
if str[0] == '[1]' {
sign = -1
start = [2]
}
for i := start; i < len(str); i++ {
if str[i] < '[3]' || str[i] > '9' {
break
}
result = result*10 + int(str[i] - '0')
}
return sign * result
}Check for '-' sign, start parsing from index 1, and ensure digits are between '0' and '9'.
