Skip to content

Commit 176ee36

Browse files
authored
Update Pair Star
1 parent f98984e commit 176ee36

File tree

1 file changed

+23
-0
lines changed
  • Course 2 - Data Structures in JAVA/Recursion Assignment

1 file changed

+23
-0
lines changed

Course 2 - Data Structures in JAVA/Recursion Assignment/Pair Star

+23
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,26 @@ aaaa
2121
Sample Output 2 :
2222
a*a*a*a
2323
*/
24+
25+
public class solution {
26+
27+
// Return the updated string
28+
public static String addStars(String s) {
29+
// Write your code here
30+
if (s.length()==1)
31+
{
32+
return s;
33+
}
34+
if (s.charAt(0)==s.charAt(1))
35+
{
36+
String smallOutput=addStars(s.substring(1));
37+
return s.charAt(0)+"*"+smallOutput;
38+
}
39+
else
40+
{
41+
String smallOutput=addStars(s.substring(1));
42+
return s.charAt(0)+smallOutput;
43+
}
44+
45+
}
46+
}

0 commit comments

Comments
 (0)