码迷,mamicode.com
首页 > 其他好文 > 详细

Code Signal_练习题_shapeArea

时间:2018-07-20 20:10:45      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:rest   ret   onclick   erp   display   efi   练习   return   sig   

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 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
View Code

Code Signal_练习题_shapeArea

标签:rest   ret   onclick   erp   display   efi   练习   return   sig   

原文地址:https://www.cnblogs.com/YD2018/p/9343248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!