867. Sum of Numbers in a Given Range
You are given two integers l and r representing the bounds of a range (inclusive). Your task is to compute the sum of all integers from l to r.
Return the sum as an integer.
Example 1:
Input: l = 2, r = 7
Output: 27
Explanation: 2 + 3 + 4 + 5 + 6 + 7 = 27
Example 2:
Input: l = 5, r = 9
Output: 35
Explanation: 5 + 6 + 7 + 8 + 9 = 35
Now Your Turn!
Pick the correct output for the given inputInput: l = 1000, r = 1005
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ l ≤r ≤ 106
- The result will always fit within a 64-bit signed integer.