Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

A simple math.. take care of data overflow though.

class Solution {
public:
    int arrangeCoins(int n) {
        if(n < 0) return -1;
        return sqrt((long long)2 * n + 0.25) - 0.5;
    }
};
posted on 2016-10-31 10:55  Tonix  阅读(94)  评论(0)    收藏  举报