8000 0344 reverse-string · malipramod/leetcode-js@c7fd2d3 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit c7fd2d3

Browse files
committed
0344 reverse-string
1 parent 0b29185 commit c7fd2d3

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

easy/0344 reverse-string/readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Reverse String
2+
3+
Write a function that reverses a string. The input string is given as an array of characters char[].
4+
5+
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
6+
7+
You may assume all the characters consist of printable ascii characters.
8+
9+
## Example 1
10+
11+
Input: ["h","e","l","l","o"]
12+
13+
Output: ["o","l","l","e","h"]
14+
15+
## Example 2
16+
17+
Input: ["H","a","n","n","a","h"]
18+
19+
Output: ["h","a","n","n","a","H"]
20+
21+
## More Info
22+
23+
<https://leetcode.com/problems/reverse-string/>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {character[]} s
3+
* @return {void} Do not return anything, modify s in-place instead.
4+
*/
5+
var reverseString = function (s) {
6+
// s.reverse(); //inbuild function
7+
if(!s.length) return;
8+
reverse(s, 0, s.length - 1); //Recursion
9+
};
10+
11+
var reverse = function (s, i, j) {
12+
if (i >= j) return;
13+
let temp = s[i];
14+
s[i] = s[j];
15+
s[j] = temp;
16+
i++; j--;
17+
return reverse(s, i, j);
18+
}
19+
reverseString(["H", "a", "n", "n", "a", "h"])

easy/0345 reverse-vowels-of-a-string/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ Output: "leotcede"
1717
## Note
1818

1919
The vowels does not include the letter "y".
20+
21+
## More Info
22+
23+
<https://leetcode.com/problems/reverse-string/>

medium/1138 alphabet-board-path/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ Output: "RR!DDRR!UUL!R!"
4040
1 <= target.length <= 100
4141

4242
target consists only of English lowercase letters.
43+
44+
## More Info
45+
46+
<https://leetcode.com/problems/alphabet-board-path/>

0 commit comments

Comments
 (0)
0