Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.11 KB

_2942. Find Words Containing Character.md

File metadata and controls

51 lines (38 loc) · 1.11 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 06, 2024

Last updated : July 01, 2024


Related Topics : Array, String

Acceptance Rate : 88.74 %


Solutions

C

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findWordsContaining(char** words, int wordsSize, char x, int* returnSize) {
    int* output = (int*) malloc(sizeof(int) * wordsSize);
    int outputPtr = 0;

    for (int i = 0; i < wordsSize; i++) {
        int temp = 0;
        while (words[i][temp]) {
            if (words[i][temp] == x) {
                output[outputPtr] = i;
                outputPtr++;
                break;
            }

            temp++;
        }
    }

    *returnSize = outputPtr;
    return output;
}