Leetcode Longest Substring Without Repeating Characters problem solution in C programming

In the Leetcode Longest Substring Without Repeating Characters problem solution in C programming Given a string s, find the length of the longest substring without repeating characters.

Leetcode Longest Substring Without Repeating Characters problem solution in C programming

int lengthOfLongestSubstring(char *s)
{
    int i, j, count = 0, lenth = 0, maxlenth = 0 , temp;

    for (i = 0; i < strlen(s); i++)
    {
        // printf("the lenth befor the loop %d \n the maxlenth before the loop %d \n", lenth, maxlenth);
            // printf("the lenth and count in the loop is %d %d\n" , lenth , count);
        for (j = i; j > count; j--)
        {
            if (s[i] == s[j - 1])
            {
                count++;
                i = count;
                lenth = 0;
                break;
            }
        }
        lenth++;
        if (maxlenth < lenth)
        {
            maxlenth = lenth;
        }
        // printf("the lenth after the loop %d \n the maxlenth after the loop %d \n", lenth, maxlenth);
    }
    return maxlenth;
}

Also read,

By Neha Singhal

Hi, my name is Neha singhal a software engineer and coder by profession. I like to solve coding problems that give me the power to write posts for this site.

Leave a Reply

Your email address will not be published. Required fields are marked *