小工具知识网

当前位置: 首页 > 行业知识 > 【力扣 - 字母异位词分组】

行业知识

【力扣 - 字母异位词分组】

2026-11-01 06:11:48 来源:互联网转载

题目描述

���你一个字符串数组,请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。

()

字母异位词 是由重新排列源单词的所有字母得到的一个新单词。

示例 1:

输入: strs = ["eat", "tea", "tan", "ate", "nat", "bat"]

()

输出: [["bat"],["nat","tan"],["ate","eat","tea"]]

示例 2:

输入: strs = [""]

输出: [[""]]

示例 3:

输入: strs = ["a"]

输出: [["a"]]

提示:

  • 1 char str[STR_SIZE]; // Key is the string int row; // Value is the row where the result is located struct Node *next;} HashNode;// Function to calculate the hash value for a stringint hash(char *str, int size) { long h = 0; for (int i = 0; i row = row; q->next = head->next; head->next = q;}// Function to get the row of a string in the hashtableint getRows(HashNode *hashtable, char *str, int size) { HashNode *head = &hashtable[hash(str, size)]; HashNode *tail = head->next; while (tail) { if (strcmp(tail->str, str) == 0) return tail->row; tail = tail->next; } return -1;}// Comparison function for qsortint cmp(const void *a, const void *b) { return *(char *)a - *(char *)b;}// Main function to group anagramschar ***groupAnagrams(char **strs, int strsSize, int *retSize, int **columnSizes) { if (strsSize == 0 || strs == NULL) { *retSize = 0; return NULL; } HashNode *hashtable = malloc(sizeof(HashNode) * strsSize); memset(hashtable, 0, sizeof(HashNode) * strsSize); char ***ans = malloc(sizeof(char **) * strsSize); *retSize = 0; *columnSizes = malloc(sizeof(int) * strsSize); for (int i = 0; i

上一篇:入侵服务器反诈骗怎么解除?

下一篇:皇冠水草栽种秘籍,轻松打造生机勃勃的水草家园!