Code Signal_练习题_shapeArea

1-interesting polygon is just a square with a side of length 1. An n-interesting polygon is obtained by taking the n - 1-interesting polygon and appending 1-interesting polygons to its rim, side by side. You can see the 1-, 2-, 3- and 4-interesting polygons in the picture below.

Code Signal_练习题_shapeArea

Example

    • For n = 2, the output should be
      shapeArea(n) = 5;
    • For n = 3, the output should be
      shapeArea(n) = 13.

我的解答:

def shapeArea(n):
return 2*n*n - 2*n + 1

膜拜大佬:

def shapeArea(n):
return n**2 + (n-1)**2
上一篇:精通css 高级web标准解决方案——可视化格式模型-盒模型


下一篇:CSS - 视觉格式化模型(Visual formatting model)