441. Arranging Coins
来源:互联网 发布:易语言硬件断点源码 编辑:程序博客网 时间:2024/06/01 13:23
Description: You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.
Given n, find the total number of full staircase rows that can be formed.
n is a non-negative integer and fits within the range of a 32-bit signed integer.
Example 1:
n = 5The coins can form the following rows:¤¤ ¤¤ ¤Because the 3rd row is incomplete, we return 2.
Example 2:
n = 8The coins can form the following rows:¤¤ ¤¤ ¤ ¤¤ ¤Because the 4th row is incomplete, we return 3.
解题思路
利用给定的n不停的减去1,2…,直至n小于要减去的数字。
Java-Solution
public class Solution { public int arrangeCoins(int n) { if(n < 0) return -1; int result = 0; int add = 1; while(n >= add){ n -= add; add++; result++; } return result; }}
0 0
- LeetCode 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- LeetCode 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- leetcode 441. Arranging Coins
- 441. Arranging Coins
- Leetcode: 441. Arranging Coins
- LeetCode 441. Arranging Coins
- 441. Arranging Coins
- 【LeetCode】 441. Arranging Coins
- LeetCode 441. Arranging Coins
- [leetcode]441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins*
- Android压缩图片到100K以下并保持不失真的高效方法
- 从一个bug说jquery的事件注册和触发机制
- android开发之百度统计
- android上传文件到服务器(图片、文本等)
- [LeetCode]Merge Sorted Array
- 441. Arranging Coins
- HighQualityAudio-FFMPEG
- Android"挂逼"修炼之行---微信摇骰子和猜拳作弊器原理解析
- typecho极验验证插件
- mysql 存储过程,执行结果"Error Code: 1329. No data - zero rows fetched, selected, or processed"
- 圆桌会议
- Keepalived无法绑定VIP故障排查经历
- IE7兼容and工作总结
- 含k个3的数