when I test ["10","6","9","3","+","-11","","/","","17","+","5","+"],
in this program, the result I got is 12, I think I am right. Because when I calculate 6/(-132) = -1, not 0, so i think the result is 12 not 22.
You're using Python, right? I think it's because in java, 6/(-132) = 0 (java use truncation).
You should use int(float(a)/b) (in this case, a=6 and b=-132) and you can get the same result with the answer
Yes, you were right. Anyway, if the user is using python, the results should be validated with the results obtained in Python. Thanks for the info with the casts.
Just got the same problem!
Python program got wrong answer!
I think the OnlineJudge should consider more about diffrent language.
6/(-132) = -1, because Python try to Integer toward 0.
if a % b != 0 and a / b < 0: temp = a / b + 1 else: temp = a / b
I got the same issue. I think it's OK evaluate Python with same standard answer. But need to clarify the rule of negative integer division on the question page (or display this test case on the page)
No it shouldn't. If you are preparing yourself for an interview they will also evaluate your knowledge in the language you use. However it won't probably be considered as a terrible mistake. I didn't remember this Python division issue either, so I'm glad I step into this problem here and not in a real interview.
this problem means the Admin who is creating the test case didn't think thoroughly.
They should consider the language compatibility. No excuse.
@whglamrock Don't complain. If you are working on so many languages all together, you will know how hard it is to keep track of everything
if using Math.round, 6/(-132) will evaluate to -0, however in another test case (4 + (13 / 5)) -> 6, 13/5 will evaluate to 3. If using Math.floor, the first will evaluate to -1 the second will evaluate to 2.
I used Python 3 on PyCharm, and the result is the same as the answer. But if I run it on LeetCode, the result is -1. You can use int(operator.truediv(a, b)) or int(float(a)/b) etc.
@ethdragon I found just use parseInt() is OK
Exactly the same problem. I think the solution should be generated using the same language as the submission does.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.