Skip to content

Commit 834e987

Browse files
committed
Add solution #344
1 parent 1f21ca1 commit 834e987

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
283|[Move Zeroes](./0283-move-zeroes.js)|Easy|
102102
326|[Power of Three](./0326-power-of-three.js)|Easy|
103103
342|[Power of Four](./0342-power-of-four.js)|Easy|
104+
344|[Reverse String](./0344-reverse-string.js)|Easy|
104105
345|[Reverse Vowels of a String](./0345-reverse-vowels-of-a-string.js)|Easy|
105106
347|[Top K Frequent Elements](./0347-top-k-frequent-elements.js)|Medium|
106107
349|[Intersection of Two Arrays](./0349-intersection-of-two-arrays.js)|Easy|

solutions/0344-reverse-string.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* 344. Reverse String
3+
* https://leetcode.com/problems/reverse-string/
4+
* Difficulty: Easy
5+
*
6+
* Write a function that reverses a string. The input string is given as an array
7+
* of characters s.
8+
*
9+
* You must do this by modifying the input array in-place with O(1) extra memory.
10+
*/
11+
12+
/**
13+
* @param {character[]} s
14+
* @return {void} Do not return anything, modify s in-place instead.
15+
*/
16+
var reverseString = function(s) {
17+
for (let i = 0; i < Math.floor(s.length / 2); i++) {
18+
[s[s.length - 1 - i], s[i]] = [s[i], s[s.length - 1 - i]];
19+
}
20+
};

0 commit comments

Comments
 (0)