Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.12 KB

_1317. Convert Integer to the Sum of Two No-Zero Integers.md

File metadata and controls

58 lines (42 loc) · 1.12 KB

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

Back to top


First completed : June 04, 2024

Last updated : July 01, 2024


Related Topics : Math

Acceptance Rate : 54.03 %


Solutions

C

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */

bool containsZero(int n) {
    while (n > 0) {
        if (n % 10 == 0) {
            return true;
        }
        n /= 10;
    }

    return false;
}

int* getNoZeroIntegers(int n, int* returnSize) {
    int* output = (int*) malloc(sizeof(int) * 2);

    for (int i = 1; i < n; i++) {
        if (!containsZero(n - i) && !containsZero(i)) {
            output[0] = n - i;
            output[1] = i;
            break; 
        }
    }
    
    *returnSize = 2;
    return output;
    
}