欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > C语言 | Leetcode C语言题解之第205题同构字符串

C语言 | Leetcode C语言题解之第205题同构字符串

2026/6/2 16:46:13 来源:https://blog.csdn.net/m0_59237910/article/details/140075472  浏览:    关键词:C语言 | Leetcode C语言题解之第205题同构字符串

题目:

题解:

struct HashTable {char key;char val;UT_hash_handle hh;
};bool isIsomorphic(char* s, char* t) {struct HashTable* s2t = NULL;struct HashTable* t2s = NULL;int len = strlen(s);for (int i = 0; i < len; ++i) {char x = s[i], y = t[i];struct HashTable *tmp1, *tmp2;HASH_FIND(hh, s2t, &x, sizeof(char), tmp1);HASH_FIND(hh, t2s, &y, sizeof(char), tmp2);if (tmp1 != NULL) {if (tmp1->val != y) {return false;}} else {tmp1 = malloc(sizeof(struct HashTable));tmp1->key = x;tmp1->val = y;HASH_ADD(hh, s2t, key, sizeof(char), tmp1);}if (tmp2 != NULL) {if (tmp2->val != x) {return false;}} else {tmp2 = malloc(sizeof(struct HashTable));tmp2->key = y;tmp2->val = x;HASH_ADD(hh, t2s, key, sizeof(char), tmp2);}}return true;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词