Arranging Coins
来源:互联网 发布:视频翻译字幕软件 编辑:程序博客网 时间:2024/06/06 14:24
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.
问题描述
你有n个硬币,第k级台阶放k个硬币,比如第1级放1个硬币,第2级放2个硬币,请问这n个硬币可以按这种方式摆上几级台阶(纯白话翻译)
解法一:
思路:
数学问题,等差数列求和。。(1+k)k/2 = n….已知n求解k,用求根公式。。。
Code:
public class Solution { public int arrangeCoins(int n) { return (int)((-1 + Math.sqrt(1 + 8*(long)n))/2); }}
0 0
- Arranging Coins
- Arranging Coins
- Arranging Coins
- Arranging Coins
- Arranging Coins
- Arranging Coins
- Arranging Coins
- LeetCode 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- 441. Arranging Coins
- LeetCode Arranging Coins
- 441. Arranging Coins
- LeetCode 441. Arranging Coins
- 441. Arranging Coins
- [leetcode 441]Arranging Coins
- 441. Arranging Coins
- leetcode 441. Arranging Coins
- JavaSE 学习参考:类的定义
- HDU 2222 AC自动机模板
- uva11178 Morley's Theorem
- 欢迎使用CSDN-markdown编辑器
- jsp引入页面,即包含文件的两种方法介绍
- Arranging Coins
- Unity与Unity Remote真机远程连调
- 如何建立自己的代码版本控制
- 【Bzoj2875】随机数生成器
- 第四章 Controller接口控制器详解(6)
- linux下提示bash:command not found
- Codeforces 777C Alyona and Spreadsheet DP
- 第四章 Controller接口控制器详解(7 完)
- mxnet 使用自己的图片数据训练CNN模型