String to Integer (atoi) 【力扣】答错了?
String to Integer (atoi) [Leetcode] gave wrong answer?
本题是实现atoi将字符串转换为整数。
当测试输入 = " +0 123"
我的代码return = 123
但为什么预期答案 = 0?
======================
如果测试输入=“+0123”
我的代码return = 123
现在预期答案 = 123
那么这个答案错了吗?
我认为这是预期的结果
Requirements for atoi:
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.
你的第一个测试用例在两个不同的数字组之间有一个space,atoi只考虑第一组'0'并转换为整数
本题是实现atoi将字符串转换为整数。
当测试输入 = " +0 123"
我的代码return = 123
但为什么预期答案 = 0?
======================
如果测试输入=“+0123”
我的代码return = 123
现在预期答案 = 123
那么这个答案错了吗?
我认为这是预期的结果
Requirements for atoi: 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.
你的第一个测试用例在两个不同的数字组之间有一个space,atoi只考虑第一组'0'并转换为整数