Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 26, 2016 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/ff846e884ef9e9e2856a to your computer and use it in GitHub Desktop.
Save jianminchen/ff846e884ef9e9e2856a to your computer and use it in GitHub Desktop.
Two string - Java - Scanner, nextInt, next(), toCharArray
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
char[] s1 = sc.next().toCharArray();
char[] s2 = sc.next().toCharArray();
int[] chs = new int[1000];
for(int i = 0; i < s1.length; i++){
chs[s1[i]]++;
}
String result = "NO";
for(int i = 0; i < s2.length; i++){
if(chs[s2[i]]>0){
result = "YES";
break;
}
}
System.out.println(result);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment