We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticStringtwoStrings(Strings1,Strings2){boolean[]charPresence=newboolean[26];// a to z// Mark characters present in the arrayfor(charc:s1.toCharArray()){charPresence[c-'a']=true;}// Check if any character in the second string exists in the arrayfor(charc:s2.toCharArray()){if(charPresence[c-'a']){return"YES";// Common character found}}return"NO";// No common character found}
Cookie support is required to access HackerRank
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 →
Java: