Code Signal_练习题_shapeArea
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
.
我的解答:
def shapeArea(n):
return 2*n*n - 2*n + 1
膜拜大佬:
def shapeArea(n):
return n**2 + (n-1)**2
Code Signal_练习题_shapeArea的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- python http post json
直接上代码吧 #coding=utf-8 import os import urllib import urllib2 import re import cookielib import json h ...
- 使用hex编码绕过主机卫士IIS版本继续注入
本文作者:非主流 测试文件的源码如下: 我们先直接加上单引号试试: http://192.168.0.20/conn.asp?id=1%27 很好,没有报错.那我们继续,and 1=1 和and 1= ...
- 逆向工程生成的Mapper.xml以及*Example.java详解
逆向工程生成的接口中的方法详解 在我上一篇的博客中讲解了如何使用Mybayis逆向工程针对单表自动生成mapper.java.mapper.xml.实体类,今天我们先针对mapper.java接口中的 ...
- 转MVC3介绍
第一节:Asp.Net MVC3项目介绍 让我们先看一下,一个普通的Asp.Net MVC3项目的样例,如下图所示 跟WebFrom还是有区别的,如果你已经了解Asp.Net MVC2的话,那就感觉异 ...
- rabbitmq实现一台服务器同时给指定部分的consumer发送消息(tp框架)(第六篇)
previous article: http://www.cnblogs.com/spicy/p/7989717.html 上一篇学习了,发送消息的时候用direct类型的exchange,绑定不同 ...
- 【转】如何选择Html.RenderPartial和Html.RenderAction
Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...
- Android 开发工具类 01_AppUtils
1.获取应用程序名称: 2.获取应用程序版本信息. import android.content.Context; import android.content.pm.PackageInfo; imp ...
- 【原】SPARK_MEM和SPARK_WORKER_MEMORY的区别
SPARK_MEM:设置每个Job(程序)在每个节点可用的内存量:(默认为512m) SPARK_WORKER_MEMORY:设置集群中每个节点分配的最大内存量:(默认为内存总量减去1G)
- java学习-struts基础(一)
struts发展 struts是Apache软件基金会赞助的一个开源项目,是一个基于Java EE的MVC开源实现. 它为Servlet/JSP技术的应用提供技术框架2001.7--Struts1正式 ...
- Maven Source Plugin
项目pom文件build下添加配置: 01 <plugin> 02 <groupId>org.apache.maven.plugins</groupId> 03 & ...