GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Create 541_Reverse_String_II (#11) · pengaoao/leetcode@d8d138d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • python
    • 541_Reverse_String_II.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎python/541_Reverse_String_II.py‎

Copy file name to clipboard
+17Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.