Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Repeat-a-string/Swift/repeat-a-string-5.swift
Normal file
19
Task/Repeat-a-string/Swift/repeat-a-string-5.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
extension String {
|
||||
func repeatBiterative(count: Int) -> String {
|
||||
var reduceCount = count
|
||||
var result = ""
|
||||
var doubled = self
|
||||
while reduceCount != 0 {
|
||||
if reduceCount & 1 == 1 {
|
||||
result.appendContentsOf(doubled)
|
||||
}
|
||||
reduceCount >>= 1
|
||||
if reduceCount != 0 {
|
||||
doubled.appendContentsOf(doubled)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
"He".repeatBiterative(5)
|
||||
Loading…
Add table
Add a link
Reference in a new issue