Created
March 26, 2016 05:03
-
-
Save jianminchen/1eb02a940f7fa4b6a3f7 to your computer and use it in GitHub Desktop.
Two string - java - HashSet, Set, Character, String class
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
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