forked from changqing16/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.cpp
More file actions
39 lines (34 loc) · 734 Bytes
/
3.cpp
File metadata and controls
39 lines (34 loc) · 734 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
#include <cstring>
#include <stdio.h>
#include <string>
using namespace std;
int mark[256];
int lengthOfLongestSubstring(string s)
{
int size = s.size();
char str[size];
strcpy(str, s.c_str());
int count = 0, ans = 0, pre = 0;
for (int i = 0; i < 256; i++)
mark[i] = -1;
memset(mark, -1, 256);
for (int i = 0; i < size; i++)
{
int change = str[i];
if (pre <= mark[change])
{
pre = mark[change] + 1;
count = i - pre; //这儿少加了1,在后面加了
}
mark[change] = i;
count++;
if (count > ans)
ans = count;
}
return ans;
}
int main()
{
int str[10];
printf("%d",sizeof(str));
}