나는 이렇게 학습한다/Algorithm & SQL
1203. String repeat
daco2020
2022. 12. 4. 01:02
Write a function that accepts an integer n and a string s as parameters, and returns a string of s repeated exactly n times.
Examples (input -> output)
6, "I" -> "IIIIII"
5, "Hello" -> "HelloHelloHelloHelloHello"
Solution:
String repeatString(int n, String s) {
String result = '';
for (int i=0; i<n; i++) {
result += s;
}
return result;
}
String repeatString(int n, String s) => s * n;