# Such a shitty problem

• The description is not clear not all unless you click on the hint. What's the point of testing all the "+-1" or "-+1" without any input spec nor any situation where input is obtained.

• This post is deleted!

• It is not a "shitty" problem and actually this is quite a normal question in interview. Implementation of such functions are often asked by companies who are doing system level programming. However, you can definitely ask questions about the requirements.

Also, you can have a look at the c function api doc:
http://www.cplusplus.com/reference/cstdlib/atoi/

This will make the problem clearer.

• Problem is though, in an actual interview you can ask for clarification but on leetcode? Duh.

• I tried 10 times and finally succeed. Test cases are very very......

• I agree I had to create a ugly solution based on the test case that was failing but I understand the point too for the test cases.
In short not too excited with this one.

``````class Solution(object):
def myAtoi(self, str):
"""
:type str: str
:rtype: int
"""
d = {'9': 9, '3': 3, '7': 7, '4': 4, '6': 6, '0': 0, '1': 1, '2': 2, '8': 8, '5': 5}
num = False
neg = False
result = 0
pos = False
for i in str:
if i==" ":
if (neg or pos) and not num:
return 0
if num:
break
elif i == "-":
if neg:
return 0
neg = True
elif i == "+":
if pos:
return 0
pos = True
elif i in d:
result = result * 10 + d[i]
num = True
else:
break
if neg and pos:
return 0
if num:
result = result*(-1 if neg else 1)
if result > (2**31-1):
result = (2**31-1)
if result < -(2**31):
result = -(2**31)
return result
return 0
`````````

• I believe that :

``````if (your head image == boy || man) {
you will get downvote;
such those shitty LeetCoders.
}
``````

Edit:

Just a joke, maybe truth :). I don't know why so many people down vote.... lol

• To tackle this kind of problem, you may feed it with some special test cases, such as " - 8" and " -8 3 ".
From the "Expected Answer" given by leetcode, you will learn that the white spaces are only allowed in the beginning.

• Sure it is, and some of tests are ....

• can not agree more !
what's the hell ‘+-2’ ...

• I have to say if I design this function, these shitty input will throw an exception directly...

• I agree, the whole point of doing leetcode is given enough information and solve the problem. If your input specs are not clear and expect we to solve it trials by trails. It is shitty.

No instruction is given and expect us to get same answer as expected. That is not how it works. If we are given all sorts of freedom for our own atoi, then why do we still have to fit our function to be exact same as expected?

PS: giving up attempt " b1351351321351". Why is that not a number and expect to be 0? This question is not about developing your own rule but to find the HIDDEN rule of solution. This is stupid.

• Totally agree. SUCH A SHITTY PROBLEM.

• This post is deleted!

• Why " + 413" should be 0 rather than 413?
Other traps are somewhat acceptable, but this one? Incredibly shitty.

• @Jossome I'm getting that issue too. So stupid. I think the way the hint was phrased, you're only supposed to remove the intial whitespace. Any whitespace after the first non-whitespace character is considered an error.

• I agree with this is shitty!

• @Jossome Did you find an answer why "+ 413" is discarded?

• @realinput Did you find an answer why +-2 should be 0?

• @IAMNOOB One clear problem with the requirement statement is that the hint refers to cplusplus.com, and cplusplus.com is incorrect about the spec of atoi in the case of unrepresentable integers. See this better reference:
http://en.cppreference.com/w/cpp/string/byte/atoi

"If the converted value falls out of range of corresponding return type, the return value is undefined."

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.