4 ms·
Nice, but it doesn't work for largest possible signed int value: -( 2147483647 + 1 ) this overflows ( in C/C++ ) I guess you could change the part of the fun
by deletes 13y ago
Nice, but it doesn't work for largest possible signed int value:
-( 2147483647 + 1 ) this overflows ( in C/C++ )
I guess you could change the part of the function to
if n > 0 {
if n%2 == 0 {
return n - 1
}
return (-n) + 1 //here
}