Last active
March 31, 2021 08:13
-
-
Save jakejakeho/e58fd630c5d8ed04fbeaeed7afd406a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
bool isSubset(vector<char> A, vector<char> B); | |
bool isSubset(vector<char> A, vector<char> B) { | |
bool map[26] = { false }; | |
for(char inA : A) | |
map[(inA - '0')] = true; | |
for(char inB : B) | |
if(!map[(inB - '0')]) | |
return false; | |
return true; | |
} | |
int main() { | |
vector<char> A = {'A', 'B', 'C', 'D', 'E'}; | |
vector<char> B = {'A', 'A', 'D', 'E'}; | |
cout << "isSubset(A,B) = " << isSubset(A,B) << endl; | |
// Computational complexity is O(n) since building the map require looping n times to build and search | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment