Notice
Recent Posts
«   2021/05   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
8
Total
11,440
관리 메뉴

## [Intro] shapeArea 본문

프로그래밍/CodeSignal

### [Intro] shapeArea

사용자 CHIqueen 2020. 3. 3. 18:11

Below we will define an n-interesting polygon. Your task is to find the area of a polygon for a given n.

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.

``````func shapeArea(n int) int {
if n==1{
return 1
}
cover := 1
for i:=2;i<n+1;i++{
cover+= i+(i-1)*2+(i-2)
}
return cover
}``````

파이썬이 아니라 Go로 풀었던 문제

하지만 정답은 매우 간단했다고 한다.

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

#### '프로그래밍 > CodeSignal' 카테고리의 다른 글

 [Intro] All Longest Strings  (0) 2020.03.11 2020.03.11 2020.03.03 2020.03.03 2020.03.03 2020.02.26