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
- SQL
- map
- 위코드
- LOWER
- Sorted
- iNT
- STR
- index
- slice
- If
- list
- or
- js
- Python
- count
- range
- WECODE
- 파이썬
- len
- split
- decorator
- DART
- sum
- enumerate
- and
- join
- Algorithm
- FOR
- lambda
- MAX
Archives
- Today
- Total
코드로 우주평화
1202. Count by X 본문
Create a function with two arguments that will return an array of the first n multiples of x.
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array or list ( depending on language ).
Examples
countBy(1,10) === [1,2,3,4,5,6,7,8,9,10]
countBy(2,5) === [2,4,6,8,10]
Solution:
List<int> countBy(int x, int n) {
List<int> results = [];
for (int i=1; i<=n; i++) {
results.add(i*x);
}
return results;
}
List<int> countBy(int c, int x) => List.generate(x, (i) => (i + 1) * c);
List<int> countBy(int x, int n) {
return [for(var i = 1; i<=n; i++) x*i];
}
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1204. Odd or Even? (0) | 2022.12.04 |
---|---|
1203. String repeat (0) | 2022.12.04 |
1201. Is the string uppercase? (0) | 2022.12.01 |
1130. Square(n) Sum (0) | 2022.11.30 |
1129. Bin to Decimal (0) | 2022.11.29 |