func myAtoi(str string) int { bytes := []byte(str) symbol := 1 var arr []byte i := 0 for;i < len(bytes) && bytes[i] == ' ';i++ {} if i < len(bytes) { if bytes[i] == '+' { symbol = 1 i++ } else if bytes[i] == '-' { symbol = -1 i++ } } for;i < len(bytes) && bytes[i] >='0' && bytes[i] <= '9'; i++ { arr = append(arr, bytes[i]) } if len(arr) != 0 { result := int64(0) max := int64(math.MaxInt32) if symbol < 0 { max = -int64(math.MinInt32) } for j := 0; j < len(arr); j++ { b := int64(arr[j] - '0') result = result * 10 + b if result > max { if symbol > 0 { return math.MaxInt32 } else { return math.MinInt32 } } } if symbol < 0 { result = -result } return int(result) } return 0}func main() { fmt.Println(myAtoi("+42")) fmt.Println(myAtoi("-42")) fmt.Println(myAtoi("-042")) fmt.Println(myAtoi(" -42")) fmt.Println(myAtoi("4193 with words")) fmt.Println(myAtoi("words and 987")) fmt.Println(myAtoi("-91283472332")) fmt.Println(myAtoi("9223372036854775808"))}