Skip to content

LeetCode-tasks/Reverse-String

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Reverse String

Write a function that reverses a string. The input string is given as an array of characters s.

Example:

Input: s = ["h","e","l","l","o"]

Output: ["o","l","l","e","h"]

Constraints:

1 <= s.length <= 10^5

s[i] is a printable ascii character.

Follow up:

Do not allocate extra space for another array. You must do this by modifying the input array in-place with O(1) extra memory.

Solution in JavaScript:

var reverseString = function(s) {
    for (let i = 0; i < s.length / 2; i++) {
        let temp = s[i]
        s[i] = s[s.length - 1 - i]
        s[s.length - 1 - i] = temp
    }
};

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published