Created
April 3, 2017 01:11
-
-
Save kkuivi/2fe79bcd3d08cc8e82ef3f51e203680a to your computer and use it in GitHub Desktop.
CodeFights: ShapeArea Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int shapeArea(int n) { | |
int numMiddleBoxes = 1 + (2 * (n-1)); | |
int leftsideArea = 0; | |
int boxesToAdd = numMiddleBoxes-2; | |
while(boxesToAdd >= 1) { | |
leftsideArea += boxesToAdd; | |
boxesToAdd -= 2; | |
} | |
int area = (leftsideArea*2) + numMiddleBoxes; | |
return area; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment