Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 26, 2016 05:03
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/1eb02a940f7fa4b6a3f7 to your computer and use it in GitHub Desktop.
Save jianminchen/1eb02a940f7fa4b6a3f7 to your computer and use it in GitHub Desktop.
Two string - java - HashSet, Set, Character, String class
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
private static boolean solve(String a, String b) {
Set<Character> set = new HashSet<Character>();
for (int i = 0; i < a.length(); i++) {
set.add(a.charAt(i));
}
for (int i = 0; i < b.length(); i++) {
if (set.contains(b.charAt(i))) return true;
}
return false;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt(); in.nextLine();
for (; T > 0; T--) {
System.out.println(solve(in.nextLine(), in.nextLine()) ? "YES" : "NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment