|
|
|
|
|
by DavidVoid
347 days ago
|
|
> the algorithm will wrongfully report "false" for arrays like e.g. [INT_MIN, -1] If you have INT_MIN along with any other negative number in the array then your program has undefined behavior in C. Signed integer overflow is UB (but unsigned overflow is not). |
|
What? Why? There’s no addition needed to solve this problem. The example implementation does invert each element, which is undefined for INT_MIN, but it would be trivial to just skip INT_MIN elements (since their additive inverse is never in the set).