Is the expected value of OJ based on C/C++ or Java results?

• It seems like the expected value of OJ is based on C/C++ or Java, not python.

Given an example input ['10', '6', '9', '3', '+', '-11', '', '/', '', '17', '+', '5', '+'], the expected output with Python should be 12, instead of 22.

The point is 6/(12*(-11)) = 6/-132 =-1, instead of 0 in C/C++.

The reason of this difference is that C/C++ (and Java) specify to round towards zero for integer division.

Here we 6/-132 = -0.045. So, it will be -1 in Python, and 0 in C/C++ (and Java).

Please check this stackoverflow webpage.

• I think it is a good catch. And when you are in an interview, it would be a nice question to discuss with your interviewer. However, I think in LeetCode OJ, you probably need to fix your python solution to follow the division principle of cpp/java. @1337, do you think so?

• Thanks, Shangrila, I agree, although I think it is kind of painful and time-wasting to make specific change to fix the pseudo "bug" resulted from programming language characteristics.

• Why does python code need to adhere to java/c++ convention?

• My spyder python gives the answer of 22 for the case of ['10', '6', '9', '3', '+', '-11', '', '/', '', '17', '+', '5', '+'], but OJ got 12.

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