-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLSWRC
More file actions
34 lines (30 loc) · 672 Bytes
/
LSWRC
File metadata and controls
34 lines (30 loc) · 672 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
// Longest Substring Without Repeating Characters
class Solution {
public int lengthOfLongestSubstring(String s) {
int length = s.length();
int max_count = 0;
if (length == 0 || length == 1) {
return length;
} else {
for (int i = 0; i <= length - 2; i++) {
int[] sub = new int[128];
int temp_count = 1;
char curr1 = s.charAt(i);
sub[curr1]++;
for (int j = i + 1; j <= length - 1; j++) {
char curr2 = s.charAt(j);
if (sub[curr2] == 1) {
break;
} else {
sub[curr2]++;
temp_count++;
}
}
if (max_count < temp_count) {
max_count = temp_count;
}
}
return max_count;
}
}
}