36 lines
728 B
C++
36 lines
728 B
C++
#include <iostream>
|
|
#include <string>
|
|
#include "chapter1.hpp"
|
|
|
|
/* Prompt
|
|
Check Permutation: Given two strings, write a method to decide if
|
|
one is a permutation of the other.
|
|
*/
|
|
|
|
bool CheckPermutation(const char* s1, const char* s2,
|
|
size_t s1_len, size_t s2_len){
|
|
|
|
int letters1[255] = {};
|
|
int letters2[255] = {};
|
|
long unsigned int indx = 0;
|
|
|
|
if(s1_len != s2_len){
|
|
return false;
|
|
}
|
|
|
|
for(indx = 0; indx < s1_len; ++indx){
|
|
int li1 = static_cast<int>(s1[indx]);
|
|
int li2 = static_cast<int>(s2[indx]);
|
|
letters1[li1] += 1;
|
|
letters2[li2] += 1;
|
|
}
|
|
|
|
for(indx = 0; indx < 255; ++indx){
|
|
if (letters1[indx] != letters2[indx]){
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|