#441

Arranging Coins

pupil · 480 · lc easy +27 · verified · 48% accepted · 4,324 likes · top 33%

play →

Description

You have n coins and are building a staircase where row i requires exactly i coins. Use coins left-to-right, row by row; the last row may remain incomplete. Given n, return the count of fully completed rows.

Example 1:

Input: n = 5
Output: 2
Explanation: Because the 3rd row is incomplete, we return 2.

Example 2:

Input: n = 8
Output: 3
Explanation: Because the 4th row is incomplete, we return 3.

Code

1
2
3