Skip to content

Commit df6c535

Browse files
committed
Solution for: reverse String
1 parent e201be4 commit df6c535

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/leetcode/ReverseString.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package leetcode;
2+
3+
public class ReverseString {
4+
5+
public static void main(String[] args) {
6+
ReverseString test = new ReverseString();
7+
System.out.println(test.reverseString("hello"));
8+
}
9+
10+
public String reverseString(String s) {
11+
if(s.length()==0) return s;
12+
char[] str= s.toCharArray();
13+
int n= str.length;
14+
for(int i= 0; i<n/2;i++){
15+
char temp = str[i];
16+
str[i]=str[n-1-i];
17+
str[n-1-i] = temp;
18+
}
19+
return String.valueOf(str);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)