🌐
LeetCode
leetcode.com › problems › reverse-string-ii
Reverse String II - LeetCode
Reverse String II - Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them.
🌐
LeetCode
leetcode.com › problems › reverse-words-in-a-string-ii
Reverse Words in a String II - LeetCode
Can you solve this real interview question? Reverse Words in a String II - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
🌐
AlgoMonster
algo.monster › liteproblems › 541
541. Reverse String II - In-Depth Explanation
In-depth solution and explanation for LeetCode 541. Reverse String II in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
Reverse String - Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
🌐
WalkCCC
walkccc.me › LeetCode › problems › 541
541. Reverse String II - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
🌐
Medium
lydiaplu.medium.com › leetcode-541-reverse-string-ii-24a879b40fdd
LeetCode — 541. Reverse String II | by Pan Lu | Medium
January 31, 2024 - Reversing Characters: The characters between left and right are then reversed using a while loop and a temporary variable for swapping. Returning the Result: After all segments are processed, the character array is returned to a string.
🌐
LeetCode
leetcode.com › problems › reverse-words-in-a-string-iii
Reverse Words in a String III - LeetCode
Reverse Words in a String III - Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: Input: s = "Let's take LeetCode contest" Output: "s'teL ekat ...
🌐
AlgoMonster
algo.monster › liteproblems › 186
186. Reverse Words in a String II - In-Depth Explanation
In-depth solution and explanation for LeetCode 186. Reverse Words in a String II in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
YouTube
youtube.com › watch
LeetCode 541 | Reverse String II | Algorithm Explained (Java) - YouTube
The description reads:"Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the str...
Published   August 15, 2020
Find elsewhere
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0100-0199 › 0186.Reverse Words in a String II › README_EN.md
leetcode/solution/0100-0199/0186.Reverse Words in a String II/README_EN.md at main · doocs/leetcode
*/ function reverseWords(s: string[]): void { const n = s.length; const reverse = (i: number, j: number): void => { for (; i < j; ++i, --j) { [s[i], s[j]] = [s[j], s[i]]; } }; for (let i = 0, j = 0; j <= n; ++j) { if (s[j] === ' ') { reverse(i, j - 1); i = j + 1; } else if (j === n - 1) { reverse(i, j); } } reverse(0, n - 1); }
Author   doocs
🌐
Gitbook
aaronice.gitbook.io › lintcode › string › reverse-words-in-a-string-ii
Reverse Words in a String II | LintCode & LeetCode
public void reverseWords(char[] s){ reverseWords(s,0,s.length-1); for(int i = 0, j = 0;i <= s.length;i++){ if(i==s.length || s[i] == ' '){ reverseWords(s,j,i-1); j = i+1; } } } private void reverseWords(char[] s, int begin, int end){ while(begin ...
🌐
LeetCode
leetcode.com › problems › reverse-words-in-a-string
Reverse Words in a String - LeetCode
Can you solve this real interview question? Reverse Words in a String - Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters.
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 0500-0599 › 0541.Reverse String II › README_EN.md
leetcode/solution/0500-0599/0541.Reverse String II/README_EN.md at main · doocs/leetcode
class Solution: def reverseStr(self, s: str, k: int) -> str: cs = list(s) for i in range(0, len(cs), 2 * k): cs[i : i + k] = reversed(cs[i : i + k]) return "".join(cs) class Solution { public String reverseStr(String s, int k) { char[] cs = s.toCharArray(); int n = cs.length; for (int i = 0; i < n; i += k * 2) { for (int l = i, r = Math.min(i + k - 1, n - 1); l < r; ++l, --r) { char t = cs[l]; cs[l] = cs[r]; cs[r] = t; } } return new String(cs); } }
Author   doocs
🌐
LeetCode
leetcode.ca › all › 186.html
Leetcode 186. Reverse Words in a String II
Given an input string , reverse the string word by word.
🌐
Spark Code Hub
sparkcodehub.com › leetcode › 541 › reverse-string-ii
LeetCode 541: Reverse String II Solution in Python – A Step-by-Step Guide
k = 2, you’d flip "ab" to "ba" and "cd" to "dc," leaving "efg" as is, resulting in "bacdfeg." That’s the fun challenge of LeetCode 541: Reverse String II, an easy-to-medium problem that’s a fantastic way to practice string manipulation in Python.
🌐
Medium
medium.com › @cutesciuridae › study-note-medium-leetcode-541-reverse-string-ii-c7cb9ba4c3db
Study note: [Medium] Leetcode #541 Reverse String II | by 可愛小松鼠 Cute Squirrel | Medium
January 3, 2020 - Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them.
🌐
AlgoMap
algomap.io › question-bank › reverse-words-in-a-string-ii
Reverse Words in a String II
The key to solving the "Reverse Words in a String II" problem in-place is to use the two-step reverse technique: first reverse the whole array to get the words in the correct order, then reverse each word to restore their original spelling.
🌐
AlgoMonster
algo.monster › liteproblems › 344
344. Reverse String - In-Depth Explanation
In-depth solution and explanation for LeetCode 344. Reverse String in Python, Java, C++ and more. Intuitions, example walk through, and complexity analysis. Better than official and forum solutions.
🌐
Reddit
reddit.com › r/learnpython › reversing a string leetcode question
r/learnpython on Reddit: reversing a string LeetCode question
May 9, 2023 -

So the code goes:

s = [“h”, ”e”, ”l”, ”l”, ”o”]

s[:] = s[::-1] print(s)

This prints the reverse of s in both VSCode and on the LeetCode website ide

I tried to see if the follow would work:

s = [“h”, ”e”, ”l”, ”l”, ”o”]

s = s[::-1] print(s)

This did work but only on VSCode not on leet code. So my question is why did it work in VSCode and not LeetCode?

There’s other solutions I tried to the problem that work in VSCode but not in LeetCode shock I find it odd, am I doing something I shouldn't?