Skip to content

Commit b5bc545

Browse files
committed
Add reverse-string
1 parent c6205ff commit b5bc545

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

Easy/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Easy
4242
- [reshape-the-matrix.md](reshape-the-matrix.md)
4343
- [reverse-integer.md](reverse-integer.md)
4444
- [reverse-linked-list.md](reverse-linked-list.md)
45+
- [reverse-string.md](reverse-string.md)
4546
- [roman-to-int.md](roman-to-int.md)
4647
- [squares-of-a-sorted-array.md](squares-of-a-sorted-array.md)
4748
- [symmetric-tree.md](symmetric-tree.md)

Easy/reverse-string.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Code
2+
====
3+
4+
```go
5+
func reverseString(s []byte) {
6+
i := 0
7+
j := len(s) - 1
8+
9+
for i < j {
10+
s[i], s[j] = s[j], s[i]
11+
i += 1
12+
j -= 1
13+
}
14+
}
15+
```
16+
17+
Solution in mind
18+
================
19+
20+
- Swap front and back elements, while moving towards the centre.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Link to profile, [bhargavsnv100](https://leetcode.com/bhargavsnv100/)
77

88
| [Easy](Easy/README.md) | [Medium](Medium/README.md) | [Hard](Hard/README.md) |
99
|------------------------|----------------------------|------------------------|
10-
| 52 | 87 | 19 |
10+
| 53 | 87 | 19 |
1111

1212
Problems finished
1313
=================
@@ -56,6 +56,7 @@ Easy
5656
- [reshape-the-matrix.md](Easy/reshape-the-matrix.md)
5757
- [reverse-integer.md](Easy/reverse-integer.md)
5858
- [reverse-linked-list.md](Easy/reverse-linked-list.md)
59+
- [reverse-string.md](Easy/reverse-string.md)
5960
- [roman-to-int.md](Easy/roman-to-int.md)
6061
- [squares-of-a-sorted-array.md](Easy/squares-of-a-sorted-array.md)
6162
- [symmetric-tree.md](Easy/symmetric-tree.md)

0 commit comments

Comments
 (0)