my 0ms C Solution


  • 0
    M

    int compareVersion(char* version1, char* version2) {
    int flag = 0;
    char v1[100];
    char v2[100];
    while (*version1 != '\0' && *version2 != '\0'){
    int i = 0;
    for (; *version1 != '\0' && *version1 != '.'; i++) {v1[i] = *version1++;}
    v1[i+1] = '\0';
    i = 0;
    for (; *version2 != '\0' && *version2 != '.'; i++) {v2[i] = *version2++;}
    v2[i+1] = '\0';
    if (atoi(v1) > atoi(v2)) return 1;
    if (atoi(v1) < atoi(v2)) return -1;
    memset(v1, 0, sizeof(char) * 100);
    memset(v2, 0, sizeof(char) * 100);
    if (*version1 == '.')
    version1++;
    if (*version2 == '.')
    version2++;
    }
    if (*version1 != '\0') {while (*version1 == '0' || *version1 == '.') version1++; if (*version1 != '\0') return 1;}
    if (*version2 != '\0') {while (*version2 == '0' || *version2 == '.') version2++; if (*version2 != '\0') return -1;}
    return 0;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.