-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaPrac.java
More file actions
60 lines (36 loc) · 1.26 KB
/
JavaPrac.java
File metadata and controls
60 lines (36 loc) · 1.26 KB
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
54
55
56
57
58
59
60
class javaprac{
public static String capgeminniAlex(String word) {
if (word == null || word.isEmpty()) {
return word;
}
char currchar = word.charAt(0);
int longestStart = 0;
int longestLength = 0;
int currstart = 0;
int currlength = 1;
for (int ix = 1; ix < word.length(); ix++) {
if (word.charAt(ix) == currchar) {
currlength++;
} else {
if (currlength > longestLength) {
longestStart = currstart;
longestLength = currlength;
}
currchar = word.charAt(ix);
currstart = ix;
currlength = 1;
}
}
if (currlength > longestLength) {
longestStart = currstart;
longestLength = currlength;
}
return word.substring(longestStart, longestStart + longestLength);
}
public static void main(String[] args) {
String s = "abbb";
System.out.println(capgeminniAlex(s).length());
}
}
// output will be 3
// I messed up my interview , i will forever hold regret that i missed an open oprtuninty. , Its like missing an open goal where ther is no keeper.