-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMaddy_sol
More file actions
35 lines (28 loc) · 940 Bytes
/
Copy pathMaddy_sol
File metadata and controls
35 lines (28 loc) · 940 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
class GfG {
static int longestUniqueSubstr(String s){
int n = s.length();
int res = 0;
for (int i = 0; i < n; i++) {
// Initializing all characters as not visited
boolean[] vis = new boolean[26];
for (int j = i; j < n; j++) {
// If current character is visited
// Break the loop
if (vis[s.charAt(j) - 'a'] == true)
break;
// Else update the result if this window is
// larger, and mark current character as
// visited.
else {
res = Math.max(res, j - i + 1);
vis[s.charAt(j) - 'a'] = true;
}
}
}
return res;
}
public static void main(String[] args){
String s = "geeksforgeeks";
System.out.println(longestUniqueSubstr(s));
}
}