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,
- Leetcode Longest Substring Without Repeating Characters problem solution in C++
- Leetcode Longest Substring Without Repeating Characters problem solution in Java
- Leetcode Longest Substring Without Repeating Characters problem solution in Python
- Leetcode Longest Substring Without Repeating Characters problem solution in C#