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.
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.
Videos
WalkCCC
walkccc.me › LeetCode › problems › 344
344. Reverse String - LeetCode Solutions
LeetCode Solutions in C++23, Java, Python, MySQL, and TypeScript.
Pcoroneos
pcoroneos.com › blog › leetcode › 344-reverse-string
Leetcode 344 - Reverse String - Paul Coroneos
Write a function that reverses a string. The input string is given as an array of characters s.
GitBooks
cheonhyangzhang.gitbooks.io › leetcode-solutions › content › 344-reverse-string.html
344 Reverse String · LeetCode solutions
public class Solution { public String reverseString(String s) { int left = 0, right = s.length() - 1; char[] chars = s.toCharArray(); while (left < right) { char tmp = chars[left]; chars[left] = chars[right]; chars[right] = tmp; left ++; right --; } return new String(chars); } }
Medium
medium.com › @mushkansingh733 › leetcode-344-reverse-string-909fc1ade07c
Leetcode 344 : Reverse String. 🔹 Problem Statement | by Mushkansingh | Medium
March 5, 2025 - O(1) Space Complexity (if modifying the string in-place). Swap the first and last character, second and second-last, and so on until the middle. function reverseString(s) { let arr = s.split(''); // Convert string to array let left = 0, right = arr.length - 1; while (left < right) { // Swap characters [arr[left], arr[right]] = [arr[right], arr[left]]; left++; right--; } return arr.join(''); // Convert back to string } console.log(reverseString("hello")); // Output: "olleh"
Stack Overflow
stackoverflow.com › questions › 66214162 › 344-reverse-string-leetcode
java - 344. Reverse String LeetCode - Stack Overflow
The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. You may assume all the characters consist of printable ascii characters. class Solution { public void reverseString(char[] s) { int arrayLength = s.length - 1; System.out.print("["); for (int i = 0; i < s.length; i++) { int temp = s.length - i - 1; if (i != arrayLength) { System.out.printf("\"%s\",", s[temp]); } else { System.out.printf("\"%s\"", s[temp]); } } System.out.print("]"); }
Spark Code Hub
sparkcodehub.com › leetcode › 344 › reverse-string
LeetCode 344: Reverse String Solution in Python – A Step-by-Step Guide
For example, with s = ... complexity). ... To solve LeetCode 344: Reverse String in Python, we need to reverse the character array s in-place, swapping elements without using extra storage....
GitHub
github.com › Waqar-107 › LeetCode › blob › master › Algorithms › 344. Reverse String.cpp
LeetCode/Algorithms/344. Reverse String.cpp at master · Waqar-107/LeetCode
Solutions of problems from leetcode.com. Contribute to Waqar-107/LeetCode development by creating an account on GitHub.
Author Waqar-107
AlgoMap
algomap.io › problems › reverse-string
344. Reverse String - Leetcode Solution
The “Reverse String” problem asks you to reverse a character array s in-place.
Maxming0
maxming0.github.io › 2020 › 06 › 04 › Reverse-String
LeetCode 344 Reverse String (Python) - 小明MaxMing
""" l, r = 0, len(s) - 1 while l < r: s[l], s[r] = s[r], s[l] l += 1 r -= 1 # one pointer class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead.
Liweiwei1419
liweiwei1419.github.io › leetcode-solution › leetcode-0344-reverse-string
344. Reverse String - LeetCode Solution
public class Solution { public String reverseString(String s) { int len = s.length(); if (len < 2) { return s; } char[] chars = s.toCharArray(); reverseString(chars); return String.valueOf(chars); } private void reverseString(char[] arr) { int l = 0; int r = arr.length - 1; while (l < r) { swap(arr, l, r); l++; r--; } } private void swap(char[] arr, int l, int r) { char temp = arr[l]; arr[l] = arr[r]; arr[r] = temp; } public static void main(String[] args) { String s = "hello"; Solution solution =new Solution(); String reverseString = solution.reverseString(s); System.out.println(reverseString); } }
Gitbook
maksimdan.gitbook.io › interview-practice-problems › leetcode_sessions › 344-reverse-string
344 Reverse String | Programming Puzzles
string reverseString(string &s) { const size_t size = s.length(); const size_t size_half = s.length() / 2; int front = 0; int end = size - 1; if (size % 2 != 0) { for (int i = 0; i < size_half + 1; i++) { char temp = s[front]; s[front++] = s[end]; s[end--] = temp; } } else { for (int i = 0; i < size_half; i++) { char temp = s[front]; s[front++] = s[end]; s[end--] = temp; } } return s; }
NeetCode
neetcode.io › solutions › reverse-string
344. Reverse String - Solution & Explanation
You are given an array of characters which represents a string `s`. Write a function which reverses a string. You must do this by modifying the input array in-place with `O(1)` extra memory. **Example 1:** ```java Input: s = ["n","e","e","t"] Output: ["t","e","e","n"] ``` **Example 2:** ```java ...
Medium
medium.com › @dylanzenner › leetcode-daily-python-344-reverse-string-43efd8e5b005
LeetCode Daily (Python): # 344 Reverse String | by Dylan Zenner | Medium
January 6, 2024 - We then start a loop and basically tell our code to swap the character at the left_pointer with the character at the right_pointer then we update our pointers to progress through the string. The left_pointer will have to increase in order to move forward, and the right_pointer will have to decrease in order to move backward. After everything is said and done we will have something that looks similar to the following: def reverse(s: List) -> List: left_pointer, right_pointer = 0, len(s) - 1 while left_pointer <= right_pointer: s[left_pointer], s[right_pointer] = s[right_pointer], s[left_pointer] left_pointer += 1 right_pointer -= 1