Last active
April 1, 2022 08:10
-
-
Save esase/471852c23d6679f70b023db79c35da7b to your computer and use it in GitHub Desktop.
Reverse string [https://leetcode.com/problems/reverse-string/]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {character[]} s | |
* @return {void} Do not return anything, modify s in-place instead. | |
*/ | |
var reverseString = function(s) { | |
const inputLength = s.length - 1; | |
const end = Math.floor(inputLength / 2); | |
for (let i = 0; i <= end; i++) { | |
[s[i], s[inputLength - i]] = [s[inputLength - i], s[i]]; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment