-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
42 lines (36 loc) · 881 Bytes
/
main.c
File metadata and controls
42 lines (36 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int verifyString(char *string, char c, int size) {
int v = 1;
string[size] = '\0';
for (int i = 0 ; i < size ; i++) {
if (c == string[i]){
v = 0;
}
}
return v;
}
int lengthOfLongestSubstring(char * s){
int count = 0, k = 0, i = 0, result = 0;
char *str = (char*)malloc(sizeof(char) * strlen(s));
while (i < strlen(s)) {
if (verifyString(str, s[i], k) == 1) {
//printf("adiciona letra '%c' a string '%s'\n", s[i], str);
str[k] = s[i];
k++;
i++;
if (k >= result)
result = k;
}
else {
count++;
i = count;
k = 0;
}
}
return result;
}
int main () {
printf("%d\n", lengthOfLongestSubstring("abcabcbb"));
}