bool isAnagram(char* s, char* t) {
int record[26] = {0};
for(int i = 0; i < strlen(s);i++)
{
record[s[i] - 'a']++;
}
for(int i = 0; i < strlen(t); i++){
record[t[i] - 'a']--;
}
for(int i = 0; i < 26; i++){
if(record[i] != 0)
return false;
}
return true;
}
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){
int hash1[1001] = {0};
int hash2[1001] = {0};
for(int i = 0; i < nums1Size; i++){
hash1[nums1[i]] = 1;
}
for(int i = 0; i < nums2Size; i++){
hash2[nums2[i]] = 1;
}
int *ret = (int*)malloc(sizeof(int)*1001);
int k = 0;
for(int i = 0; i < 1001; i++){
if(hash1[i] == 1 && hash2[i] == 1){
ret[k++] = i;
}
}
(*returnSize) = k;
return ret;
}
int count(int n){
int res = 0;
int a=0;
while(n){
a = n%10;
n = n/10;
res += a*a;
}
return res;
}
bool isHappy(int n){
int fast = n,slow = n;
do{
slow = count(slow);
fast = count(fast);
fast = count(fast);
}while(slow != fast);
return (slow == 1);
}
struct hashTable {
int key;
int val;
UT_hash_handle hh;
};
struct hashTable* hashtable;
struct hashTable* find(int ikey) {
struct hashTable* tmp;
HASH_FIND_INT(hashtable, &ikey, tmp);
return tmp;
}
void insert(int ikey, int ival) {
struct hashTable* it = find(ikey);
if (it == NULL) {
struct hashTable* tmp = malloc(sizeof(struct hashTable));
tmp->key = ikey, tmp->val = ival;
HASH_ADD_INT(hashtable, key, tmp);
} else {
it->val = ival;
}
}
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
hashtable = NULL;
for (int i = 0; i < numsSize; i++) {
struct hashTable* it = find(target - nums[i]);
if (it != NULL) {
int* ret = malloc(sizeof(int) * 2);
ret[0] = it->val, ret[1] = i;
*returnSize = 2;
return ret;
}
insert(nums[i], i);
}
*returnSize = 0;
return NULL;
}