4 ms·
"Our problem will be a very simple one: sum a list of n integers. To make this fair, we will assume that the integers all fit in a 32-bit signed int, and that t
by billpg 12y ago
"Our problem will be a very simple one: sum a list of n integers. To make this fair, we will assume that the integers all fit in a 32-bit signed int, and that their sum fits in a 32-bit signed int."
What if my list is:
[2000000000, 2000000000, -2000000000, -2000000000]
- ajuc 12y agoIt will wrap around both ways and correctly return 0. At least it does on my compiler, I never remember what is part of standard C and what is accident of implementation. But it won't work for {2000000000, 2000000000}, as stated in the article.