Skip to content

Commit 418c2e2

Browse files
authored
Update Check AB
1 parent 176ee36 commit 418c2e2

File tree

1 file changed

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

1 file changed

+26
-0
lines changed

Course 2 - Data Structures in JAVA/Recursion Assignment/Check AB

+26
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@ abababa
2525
Sample Output 2 :
2626
false
2727
*/
28+
public class Solution {
29+
30+
public static boolean checkAB(String input) {
31+
// Write your code here
32+
if (input.length()==0)
33+
{
34+
return true;
35+
}
36+
37+
if (input.charAt(0) != 'a')
38+
{
39+
return false;
40+
}
41+
42+
if (input.length() >= 3 && input.substring(0,3).equals("abb"))
43+
{
44+
return checkAB(input.substring(3));
45+
}
46+
else
47+
{
48+
return checkAB(input.substring(1));
49+
}
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)