Leetcode 441 Arranging Coins

来源:互联网 发布:sql count 用法 编辑:程序博客网 时间:2024/06/06 17:55

Leetcode 441 Arranging Coins

class Solution {public:    int arrangeCoins(int n) {      int rows = 0;      int count = 1;      while(n >= count)      {         n -= count;         count ++;         rows ++;      }      return rows;    }};//magic method?class Solution {public:    int arrangeCoins(int n) {        return floor((-1 + sqrt(8.0 * n + 1)) / 2);    }};