-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepeatingString.kt
More file actions
47 lines (34 loc) · 898 Bytes
/
RepeatingString.kt
File metadata and controls
47 lines (34 loc) · 898 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package RepeatingString
class RepeatingString {
fun repeatedString(s: String, n: Long): Long {
val tempInput = s.toCharArray().toMutableList()
var countA: Long = 0
if (s == "a") return n
for (index in 0 until n) {
val tempC = tempInput[0]
tempInput.removeAt(0)
tempInput.add(tempC)
if (tempC == 'a') countA++
}
return countA
}
fun repeatedString2(s: String, n: Long): Long {
var count: Long = 0
var i = 0
while (i < s.length) {
if (s[i] == 'a')
count++
i++
}
val div = n.div(s.length)
val reminder = n.rem(s.length)
count *= div
i = 0
while (i < reminder) {
if (s[i] == 'a')
count++
i++
}
return count
}
}