Created
July 11, 2021 07:25
-
-
Save kshitijvarshne1/cee30b84ccd73e43139e875ef0d0bbb1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Created by IntelliJ IDEA. | |
* Author: Kshitij Varshney (kshitijvarshne1) | |
* Date: 16-May-21 | |
* Time: 3:06 PM | |
* File: Sample.java | |
*/ | |
public class Sample { | |
public static void main(String[] args) { | |
String[] s = {"ab", "aab", "xyz", "axb"}; | |
System.out.println(countSpecialString(s)); | |
} | |
static int countSpecialString(String[] s) { | |
int ans = 0; | |
for (String i : s) { | |
if ((check(i) == true)) { | |
ans++; | |
} | |
} | |
return ans; | |
} | |
private static boolean check(String s) { | |
for (int i = 0; i < s.length(); i++) { | |
if (s.charAt(i) != 'a') { | |
if (s.charAt(i) != 'b') { | |
return false; | |
} | |
} | |
} | |
if(s.contains("b")==false){ | |
return false; | |
} | |
if(s.contains("a")==false){ | |
return false; | |
} | |
return true; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment