You are viewing a single comment's thread. Return to all comments →
Fastest and Most Efficient Implementation Possible
def pangrams(s: String): String = { @scala.annotation.tailrec def h(ss:String,mask:Int):String= (ss,mask) match { case _ if mask==0 => "pangram" case _ if ss.isEmpty => "not pangram" case _ if ss.head.isLetter => h ( ss.drop(1), mask & ~(1<<ss.head.toLower-'a')) case _ => h(ss.drop(1),mask) } h(s,(1 << 26) - 1) } }
Alternative Way checking Bitmask Equality
public static String pangrams(String s) { int curr = 0; int mask = (1<<26) - 1; for (char c : s.toCharArray()) { if (Character.isLetter(c)) { curr |= 1 << (c-'a'); if (curr==mask) return "pangram"; } } return "not pangram";
Seems like cookies are disabled on this browser, please enable them to open this website
Pangrams
You are viewing a single comment's thread. Return to all comments →
Fastest and Most Efficient Implementation Possible
Alternative Way checking Bitmask Equality