Arranging Coins LeetCode solution in C++
1class Solution {2public:3int arrangeCoins(int n) {4int count = 0;5while (n > 0) {6count++;7n = n - count;8}9if (n == 0) // all the coins are used to make complete rows so n if fully10// uitlized till 011{12return count;13} else if (n < 0) // if the last row has not been created fully then n will14// go negative15{16return count - 1;17}18return -1; // this will never get encountered19}20};