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; } };
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; } };
上一篇:LeetCode "Minimum Moves to Equal Array Elements"
下一篇:LeetCode "448. Find All Numbers Disappeared in an Array"
【LeetCode】39. 组合总和
【LeetCode】705. 设计哈希集合
【LeetCode】706. 设计哈希映射
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M