Skip to content

Instantly share code, notes, and snippets.

@r14152
Last active August 14, 2021 14:28
Show Gist options
  • Save r14152/7aae61a6fbffdc5185341a3dd24d530f to your computer and use it in GitHub Desktop.
Save r14152/7aae61a6fbffdc5185341a3dd24d530f to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating Characters
int lengthOfLongestSubstring(char* s) {
int len = strlen(s);
int i=0,count=0,max=0;
for(i=0;i<len;i++)
{
int arr[256]={0};
count=0;
int j=0;
for(j=i;j<len;j++)
{
int k = s[j]-' ';
if(arr[k] == 0)
{
arr[k] +=1;
count++;
}
else
break;
}
if(count>max)
max = count;
if(max == len)
break;
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment