Skip to content

Commit

Permalink
Accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
Mo-Shakib committed Oct 31, 2024
1 parent b21c4ec commit c9b514d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions easy/344-reverse-string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# @lc app=leetcode id=344 lang=python3
#
# [344] Reverse String
#
# https://leetcode.com/problems/reverse-string/description/
#
# algorithms
# Easy (79.16%)
# Likes: 8757
# Dislikes: 1184
# Total Accepted: 2.9M
# Total Submissions: 3.7M
# Testcase Example: '["h","e","l","l","o"]'
#
# 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 with O(1) extra
# memory.
#
#
# Example 1:
# Input: s = ["h","e","l","l","o"]
# Output: ["o","l","l","e","h"]
# Example 2:
# Input: s = ["H","a","n","n","a","h"]
# Output: ["h","a","n","n","a","H"]
#
#
# Constraints:
#
#
# 1 <= s.length <= 10^5
# s[i] is a printable ascii character.
#
#
#

# @lc code=start
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
s = s[:-1]
return s
"""
s[:] = s[::-1]
return s

# @lc code=end

0 comments on commit c9b514d

Please sign in to comment.