You are viewing a single comment's thread. Return to all comments →
O(M+N) solution:
public static boolean hasCommonString(String s1, String s2) { return (toInt(s1) & toInt(s2)) > 0; } private static int toInt(String str) { int res = 0; for (int i = 0; i < str.length(); i++) res |= 1 << (str.charAt(i) - 'a'); return res; }
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 →
O(M+N) solution: