我们有一个字符串 s
我们有一个数字n
下面是一个函数,它采用字符串,将偶数索引字符连接到前面,将奇数索引字符连接到后面。
例子
s = "Wow Example!"
result = "WwEapeo xml!"
s = "I'm JomoPipi"
result = "ImJm ii' ooPp"
任务:
在将函数应用到字符串 n 次后,返回字符串的结果。
例如,s = “qwertyuio” 和 n = 2:
after 1 iteration s = "qetuowryi"
after 2 iterations s = "qtorieuwy"
return "qtorieuwy"
注意
有很多测试,大字符串,n大于十亿
所以准备好优化。
题目难度:一般
题目来源:String → N iterations → String | Codewars
def jumbled_string(s: str, n: int) -> str:
# you've made it this far, now finish it!
pass
assert jumbled_string("Such Wow!",1) == "Sc o!uhWw"
assert jumbled_string("better example",2) == "bexltept merae"
assert jumbled_string("qwertyuio",2) == "qtorieuwy"
assert jumbled_string("Greetings",8) == "Gtsegenri"