forked from sunnyshahabuddin/Coding-Ninjas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplaceChar.java
More file actions
32 lines (26 loc) · 771 Bytes
/
ReplaceChar.java
File metadata and controls
32 lines (26 loc) · 771 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
import java.util.Scanner;
public class Runner {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String input = s.next();
char c1 = s.next().charAt(0);
char c2 = s.next().charAt(0);
System.out.println(Solution.replaceCharacter(input, c1, c2));
}
}
public class Solution {
public static String removeConsecutiveDuplicates(String s) {
// Write your code here
String str="";
if(s.length()==1){
str=s;
return str;
}
String actual=removeConsecutiveDuplicates(s.substring(0,s.length()-1));
if(s.charAt(s.length()-1)==actual.charAt(actual.length()-1)){
return actual;
}
actual+=Character.toString(s.charAt(s.length()-1));
return actual;
}
}