Given a positive integer limit, add up the numbers 1, 2, 3, … in this order, and stop as soon as the total is at least limit. Return how many numbers you added.
The total may go past limit: the number that makes it reach or pass limit is the last one added, and it counts.
Example 1:
Input: limit = 10 Output: 4 Explanation: 1 + 2 + 3 + 4 = 10 reaches the limit exactly, so 4 numbers were added.
Example 2:
Input: limit = 11 Output: 5 Explanation: 1 + 2 + 3 + 4 = 10 is still less than 11, so 5 is added too. The total becomes 15, and 5 numbers were added.
Example 3:
Input: limit = 1 Output: 1 Explanation: The first number, 1, already reaches the limit.
Constraints:
1 <= limit <= 109
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
