반응형
leetcode.com/problems/longest-substring-without-repeating-characters/
Solution
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
42
43
44
45
46
47
48
49
50
51
52
53
|
int lengthOfLongestSubstring(char * s){
int ctable[255] = {0, };
char cmax[255];
int max_len = 0;
char ctmp[255];
int tmp_len = 0;
int idx;
int o_idx = 0;
char* o = s;
while(*s){
idx = *s - ' ';
if(ctable[idx]==0){
ctmp[tmp_len++] = *s;
ctable[idx] = 1;
}else{
if(max_len < tmp_len){
max_len = 0;
for(int i=0 ; i<tmp_len ; i++){
cmax[max_len++] = ctmp[i];
}
}
for(int i=0 ; i<tmp_len ; i++){
ctable[ctmp[i] - ' '] = 0;
}
tmp_len = 0;
s = (o + (++o_idx));
continue;
}
s++;
}
if(max_len < tmp_len){
max_len = 0;
for(int i=0 ; i<tmp_len ; i++){
cmax[max_len++] = ctmp[i];
}
}
return max_len;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Easy]14. Longest Common Prefix (0) | 2021.03.22 |
---|---|
Leetcode - [Easy]13. Roman to Integer (0) | 2021.03.14 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |
Leetcode - [Easy]9. Palindrome Number (0) | 2021.03.04 |
Leetcode - [Easy]7. Reverse Integer (0) | 2021.03.04 |