Cover image for Pocket Gems
Logo

Pocket Gems

Employeur impliqué

Pocket Gems

Ajouter un entretien

Questions d'entretien

Entretien pour Server Engineer

-

Pocket Gems

Write a function that compares two strings and returns a third string containing only the letters that appear in both.

Réponse à la question d'entretien

1 réponse

1

string getcommstring(string s1,string s2) { string s; int size1 = s1.size() ; int size2 = s2.size() ; int hash[30] ; for (int i = 0 ; i < 30 ; i++) { hash[i] = 0 ; } for ( int i = 0 ; i < size1 ; i++ ) { hash[s1[i] - 'a'] = 1 ; } for (int i = 0 ; i < size2 ; i++) { if ( hash[s2[i] - 'a'] == 1 ) { s.push_back(s2[i]) ; hash[s2[i]-'a']= 0 ; } } return s ; }

Utilisateur anonyme le

Ajouter des réponses ou des commentaires

Pour commenter ceci, connectez-vous ou inscrivez-vous.