一波N折,面向测试用例编程 ```go func myAtoi(s string) int { var ans int var isRead, isNN bool for _, c := range s{ if c == ' ' { if !isRead{ continue } break }else if c == '-' || c == '+'{ if !isRead{ isNN = c=='-' isRead = true }else{ break } }else if c >= '0' && c <= '9'{ ans *= 10 ans += int(c - '0') if !isNN { if ans > math.MaxInt32{ return math.MaxInt32 } }else{ if -ans < math.MinInt32{ return math.MinInt32 } } isRead = true }else{ break } } if isNN { return -ans } return ans } ```