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.
publicstaticintstringConstruction(Strings){// goal: determine min cost of copying string sif(s.length()==1)return1;//this solution has o(n) time, o(n) spaceSet<Character>characterSet=newHashSet<>();//iterate over each char in sfor(charc:s.toCharArray()){//if char isnt in char set, add to the total costif(!characterSet.contains(c)){characterSet.add(c);//add char into char set}}returncharacterSet.size();}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
String Construction
You are viewing a single comment's thread. Return to all comments →
My Java solution: