Data Structure & Algorithm: Level-1 Problem #11. Build Pyramid

Given a total of N regular hexagon , find out how many rows of pyramid we can build. Note that every k-th row must have exactly k hexagon.

Sample Input: 60

Sample Output: 10

Given 60 regular hexagon, we can build 10 rows of pyramid shown as below.

Hexgon Pyramid


数据结构和算法:初级练习题# 11 – 构建金字塔


给定一组N个正六边形,计算用它们可以最多构建几层高的金字塔,每一层的正六边形数量和层数相等。

输入样例:60

输出样例:10

如上图所示,60个正六边形可以构建10层完整的金字塔,剩余五个不足构建下一层金字塔。


Python Solutions

Build Pyramid