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.
- Prepare
- Algorithms
- Strings
- String Construction
- Discussions
String Construction
String Construction
+ 0 comments Python Solution
def stringConstruction(s): return len(set(s))
+ 0 comments 80% My Java Solution
public static int stringConstruction(String s) { HashMap<Character, Integer> countChar = new HashMap<Character, Integer>(); char[] s_char = s.toCharArray(); for(int i=0; i<s.length(); i++) { if(!countChar.containsKey(s_char[i])) { countChar.put(s_char[i],1); } } return countChar.size(); }
+ 0 comments JavaScript one line
function stringConstruction(s) { return new Set([...s]).size }
+ 0 comments JavaScript Solution
function stringConstruction(s) { let [i, sLength, cost] = [0, s.length, 0]; while (i < sLength) { if (!s.slice(0, i).includes(s[i])) cost++; i++; } return cost; }
+ 0 comments - c language
int stringConstruction(char* s) { int max=0;int count=0; for( int i = 0 ; i<strlen(s);i++) { if(s[i]>max) { max = s[i]; } } int *arr = (int*)calloc(max+1,sizeof(int)); for(int i = 0 ; i<strlen(s);i++) { arr[s[i]]++; } for(int i = 0 ; i<=max;i++) { if(arr[i]>0) { count++; arr[i]=0; } } free(arr); return count; }
Load more conversations
Sort 896 Discussions, By:
Please Login in order to post a comment