A 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.
Example
-
- For
n = 2
, the output should beshapeArea(n) = 5
; - For
n = 3
, the output should beshapeArea(n) = 13
.
- For
我的解答:
def shapeArea(n): return 2*n*n - 2*n + 1
膜拜大佬:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
def shapeArea(n): return n**2 + (n-1)**2