-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseString.java
More file actions
54 lines (37 loc) · 890 Bytes
/
ReverseString.java
File metadata and controls
54 lines (37 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.*;
import java.util.*;
class ReverseString{
public static void main(String[] arg){
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
System.out.println(replaceSpace(s));
}
public static String reverseString(String s){
String temp = "";
for(int i = s.length() - 1; i >= 0; i--){
temp += s.charAt(i);
}
return temp;
}
public static String removeDuplicates(String s){
boolean[] charMap = new boolean[256];
String temp = "";
for(int i = 0; i < s.length(); i++){
int val = s.charAt(i);
if(!charMap[val]){
temp += s.charAt(i);
charMap[val] = true;
}
}
return temp;
}
public static String replaceSpace(String s){
for(int i = 0; i < s.length(); i++){
if(s.charAt(i) == ' '){
s = s.substring(0, i) + "%20" + s.substring(i + 1);
i += 3;
}
}
return s;
}
}