Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 26, 2016 03:13
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/6f029bb909ed7d85c012 to your computer and use it in GitHub Desktop.
Save jianminchen/6f029bb909ed7d85c012 to your computer and use it in GitHub Desktop.
Two string - Java - thinking in Java
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
testCase:
for(int i = 0; i < N; i++) {
String left = in.next();
String right = in.next();
boolean[] leftC = new boolean[26];
for(int j = 0; j < left.length(); j++) {
leftC[left.charAt(j) - 'a'] = true;
}
for(int k = 0; k < right.length(); k++) {
if(leftC[right.charAt(k) - 'a']) {
System.out.println("YES");
continue testCase;
}
}
System.out.println("NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment