c++ simple solution


  • 0
    A

    class Solution {
    public:
    int arrangeCoins(int n) {
    int num = 0;
    int tmp = n;
    if(n == 0)
    return 0;
    for(int i = 1; i <= tmp; i++){
    n = n - i;
    if(n == 0){
    num = i;
    break;
    }
    if(n < 0){
    num = i - 1;
    break;
    }
    }
    return num;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.