Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- WECODE
- enumerate
- Sorted
- slice
- SQL
- count
- 파이썬
- decorator
- or
- index
- list
- MAX
- LOWER
- lambda
- js
- split
- 위코드
- iNT
- sum
- join
- len
- FOR
- DART
- map
- Algorithm
- Python
- and
- range
- STR
- If
Archives
- Today
- Total
코드로 우주평화
1205. Sum of Cubes 본문
Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum.
Assume that the input n will always be a positive integer.
Examples: (Input --> output)
2 --> 9 (sum of the cubes of 1 and 2 is 1 + 8)
3 --> 36 (sum of the cubes of 1, 2, and 3 is 1 + 8 + 27)
Solution:
int sumCubes(int n) {
int result = 0;
for (int i=1; i<=n; i++) {
result += i*i*i;
}
return result;
}
import 'package:collection/collection.dart';
int sumCubes(int n) {
List<int> l = new List<int>.generate(n+1, (i) => i * i * i);
return l.sum;
}
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1207. Vowel Count (0) | 2022.12.07 |
---|---|
1206. Sum of positive (0) | 2022.12.06 |
1204. Odd or Even? (0) | 2022.12.04 |
1203. String repeat (0) | 2022.12.04 |
1202. Count by X (0) | 2022.12.02 |