You are viewing a single comment's thread. Return to all comments →
My minimaist O(n + m) solution:
public static String twoStrings(String s1, String s2) { boolean[] s1_array = new boolean[26]; int base = (int)'a'; for (int i = 0 ; i < s1.length() ; i++){ int position = (int)s1.charAt(i) - base; s1_array[position] = true; } for (int i = 0 ; i < s2.length() ; i++){ int position = (int)s2.charAt(i) - base; if (s1_array[position] == true) return "YES"; } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Two Strings
You are viewing a single comment's thread. Return to all comments →
My minimaist O(n + m) solution: