3 ms·
Here is a working go implementation... http://play.golang.org/p/FgZp8xNfPt http://play.golang.org/p/FgZp8xNfPt
by ushi 13y ago
Here is a working go implementation...
http://play.golang.org/p/FgZp8xNfPt http://play.golang.org/p/FgZp8xNfPt
- deletes 13y agoNice, 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 }
- deleted 13y ago[deleted]