Skip to content

Commit d8d138d

Browse files
authored
Create 541_Reverse_String_II (qiyuangong#11)
541_Reverse_String_II by @nishithgadhiya
1 parent eaaab36 commit d8d138d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

python/541_Reverse_String_II.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def reverseStr(self, s, k):
3+
N = len(s)
4+
ans = ""
5+
position = 0
6+
while position < N:
7+
nx = s[position : position + k]
8+
ans = ans + nx[::-1] + s[position + k : position + 2 * k]
9+
position += 2 * k
10+
return ans
11+
12+
13+
14+
s1 = Solution()
15+
s="abcdefg"
16+
k=2
17+
print(s1.reverseStr(s,k))

0 commit comments

Comments
 (0)