Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e9ee867

Browse files
LC#344 day1 april challenge- reverse string
1 parent b328bbd commit e9ee867

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package LeetcodeDaily.April2022;
2+
3+
import java.util.Arrays;
4+
5+
public class Day1ReverseString344 {
6+
7+
public static void reverseString(char[] s) {
8+
9+
int start = 0, end = s.length - 1;
10+
while (start < end) {
11+
swap(s, start, end);
12+
start++;
13+
end--;
14+
}
15+
}
16+
17+
private static void swap(char[] arr, int start, int end) {
18+
char temp = arr[start];
19+
arr[start] = arr[end];
20+
arr[end] = temp;
21+
}
22+
23+
public static void main(String[] args) {
24+
char[] charr = { 'h', 'e', 'l', 'l', 'o' };
25+
System.out.println(Arrays.toString(charr));
26+
reverseString(charr);
27+
System.out.println(Arrays.toString(charr));
28+
}
29+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /