1. 程式人生 > >Leetcode——441. Arranging Coins

Leetcode——441. Arranging Coins

題目原址

題目描述

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.

Example1:

n = 5

The coins can form the following rows:
¤
¤ ¤
¤ ¤
Because the 3rd row is incomplete, we return 2.

Example2:

n = 8
The coins can form the following rows:
¤
¤ ¤
¤ ¤ ¤
¤ ¤
Because the 4th row is incomplete, we return 3.

解題思路

這個題很簡單,首先第i行有i個元素,找到最後一行滿足第i行有i個元素的行數

AC程式碼

class Solution {
    public int arrangeCoins(int n) {
        int row = 1;
        while(n >= row) {
            n = n - row;
            row ++;
        }
        return row - 1 ;

    }
}

相關推薦

Leetcode 441 Arranging Coins

shu gin amd fdt tco www. ipo mar leetcode 7Wx笨講5亂73K5盒http://jz.docin.com/dmt708 棕木畢6y巫喚06嘏http://www.docin.com/app/user/userinfo?userid

LeetCode 441. Arranging Coins

form following n-n win ems 標簽 example lan 3rd You have a total of n coins that you want to form in a staircase shape, where every k-th

[LeetCode] 441. Arranging Coins 排列硬幣

solution light stair coin sel math.sqrt object 硬幣 code You have a total of n coins that you want to form in a staircase shape, where ever

Leetcode 441. Arranging Coins 硬幣放置 解題報告

1 解題思想 這道題可以理解了為給了n個硬幣,然後需要你按照這個規則: 第i層放i個硬幣 那麼,這n個硬幣,能夠完整的擺好多少層,比如說在第五層時只放了3個,那麼完整的擺了4層,輸出4 這道題直

Leetcode——441. Arranging Coins

題目原址 題目描述 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 coin

LeetCode.441 Arranging Coins (經典數列求和應用)

題目: 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, f

leetcodeArranging Coins441

題目: 你總共有 n 枚硬幣,你需要將它們擺成一個階梯形狀,第 k 行就必須正好有 k 枚硬幣。 給定一個數字 n,找出可形成完整階梯行的總行數。 n 是一個非負整數,並且在32位有符號整型的範圍內。 示

441. Arranging Coins(python+cpp)

題目: You have a total of n coins that you want to form in a staircase shape, where every k-th row mus

leetcodeArranging Coins

Title:Arranging Coins    441 Difficulty:Easy 原題leetcode地址:   https://leetcode.com/problems/arranging-coins/   1. 數學

C#LeetCode刷題之#441-排列硬幣(Arranging Coins

問題 你總共有 n 枚硬幣,你需要將它們擺成一個階梯形狀,第 k 行就必須正好有 k 枚硬幣。 給定一個數字 n,找出可形成完整階梯行的總行數。 n 是一個非負整數,並且在32位有符號整型的範圍內。 n = 5 硬幣可排列成以下幾行: ¤ ¤ ¤ ¤ ¤ 因為第

[LeetCode] Arranging Coins

總數 style 方程 stair row bsp nbsp sha arr You have a total of n coins that you want to form in a staircase shape, where every k-th row must

LeetCode演算法題-Arranging Coins(Java實現)

這是悅樂書的第229次更新,第241篇原創 01 看題和準備 今天介紹的是LeetCode演算法題中Easy級別的第96題(順位題號是441)。您想要以樓梯形狀形成總共n個硬幣,其中每個第k行必須具有恰好k個硬幣。給定n,找到可以形成的完整樓梯行的總數。n是一個非負整數,適合32位有符號整數的範圍。例如

Leetcode】【python】Arranging Coins

Arranging Coins 標準答案程式碼來自書影部落格 題目大意 你有n枚硬幣,想要組成一個階梯形狀,其中第k行放置k枚硬幣。 給定n,計算可以形成的滿階梯的最大行數。 n是非負整數,並且在32位帶符號整數範圍之內。 解題思路 數

leetcode 441. 排列硬幣

必須 style 開始 個數字 coins 添加 range div 一行 你總共有 n 枚硬幣,你需要將它們擺成一個階梯形狀,第 k 行就必須正好有 k 枚硬幣。 給定一個數字 n,找出可形成完整階梯行的總行數。 n 是一個非負整數,並且在32位有符號整型的範圍內。 示例

138.Arranging Coins

code 其中 復雜 gin ins 當前 前行 開始 range 題目: You have a total of n coins that you want to form in a staircase shape, where every k-th row must h

LeetCode--441--排列硬幣

-c 並且 排列 -- ron coin self 給定 object 問題描述: 你總共有 n 枚硬幣,你需要將它們擺成一個階梯形狀,第 k 行就必須正好有 k 枚硬幣。 給定一個數字 n,找出可形成完整階梯行的總行數。 n 是一個非負整數,並且在32位有符號整型的範圍內

Arranging Coins

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. G

Arranging Coins問題及解法

問題描述: You have a total ofncoins that you want to form in a staircase shape, where everyk-th row must have exactlykcoins. Givenn, find th

[LeetCode]160.Intersection of Two Linked Lists

col style return tro nod sts diff original you Intersection of Two Linked Lists Write a program to find the node at which the intersectio

[LeetCode] Reshape the Matrix 矩陣重塑

ren ati num 我們 資料 call posit tar led In MATLAB, there is a very useful function called ‘reshape‘, which can reshape a matrix into a ne