leetcode oj java arrangecoins
来源:互联网 发布:如何网络共享打印机 编辑:程序博客网 时间:2024/06/16 11:58
一、问题描述
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.
二、思路:
叠加计数:
三、代码:
public int arrangeCoins(int n) { int i = 0; int sum = 0; for (i = 1; sum <= n - i; i++) { sum += i; } return (i - 1); }
0 0
- leetcode oj java arrangecoins
- leetcode oj java Path Sum
- leetcode oj java Rectangle Area
- leetcode oj java Submission Details
- leetcode oj java - Rotate Array
- leetcode oj java Fizz Buzz
- leetcode oj java Longest Palindrome
- leetcode oj java Binary Watch
- leetcode oj java Add Strings
- leetcode oj java Burst Balloons
- leetcode oj java Decode String
- leetcode oj java Gray Code
- leetcode oj java Unique Paths
- leetcode oj java Counting Bits
- leetcode oj java 475. Heaters
- LeetCode OJ | Two Sum(java版)
- leetcode oj java Implement Stack using Queues
- leetcode oj java Excel Sheet Column Title
- centos如何进入图形界面和centos已经进到图形界面后怎么打开命令行
- Android-使用OpengGL实现的Canvas进行绘制(简单介绍)
- Atitit 代理与分销系统(1) 子代理 充值总额功能设计概览 sum() groubpy subagt
- php连接mysql
- MardownDemo
- leetcode oj java arrangecoins
- javascripts页面跳转
- Android 资源整合
- JS设置cookie、读取cookie、删除cookie
- 自治事务和变异表的行级触发器部分问题
- spark初窥
- Atitti css transition Animation differ区别
- 广度优先搜索
- java 贪吃蛇之我的实现