DESCRIPTION:
Given the triangle of consecutive odd numbers:
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output)
1 --> 1
2 --> 3 + 5 = 8
def row_sum_odd_numbers(n):
print("num:" ,n)
row_start=1-n+n**2
print(row_start)
ans=0
for i in range(n):
ans+=row_start+2*i
print(ans)
return ans'알고리즘 문제 > CodeWar' 카테고리의 다른 글
| Persistent Bugger (0) | 2022.09.21 |
|---|---|
| String ends with? (0) | 2022.09.20 |
| Duplicate Encoder (0) | 2022.09.20 |
| Are they the "same"? (0) | 2022.09.20 |
| Isograms (1) | 2022.09.19 |