Skip to content

Instantly share code, notes, and snippets.

@kshitijvarshne1
Created July 11, 2021 07:25
Show Gist options
  • Save kshitijvarshne1/cee30b84ccd73e43139e875ef0d0bbb1 to your computer and use it in GitHub Desktop.
Save kshitijvarshne1/cee30b84ccd73e43139e875ef0d0bbb1 to your computer and use it in GitHub Desktop.
/* 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