- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep1.java
More file actions
Latest commit
50 lines (47 loc) · 918 Bytes
/
Copy pathstep1.java
File metadata and controls
50 lines (47 loc) · 918 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
40
41
42
43
44
45
46
47
48
49
50
/* "aabbbbcccd"
“”
“a”
“aadddd”
“aaaadd” */
// returns longest substring of repeated characters in str
stringsolve(stringstr){
stringres=””;
intN=str.length();
for(inti=0;i!=N;i++){
charc=str.charAt(i);
intj=i+1;
while(j!=N && str.chatAt(j) == c)){
j++;
}
if(j-i > res.length()) res=str.substring(i,j);
i=j-1;
}
returnres;
}
/* 012 → 020
222 1000
0
1
2
20
21
212
3
-1
-10 → -2 */
// Takes a string of base 3, returns that string + 1 in base 3
stringsolve2 (stringstr){
stringres= ””;
if(str.length()==0) //throw an exception
inti=str.length()-1;
while(i!=-1 && str.charAt(i) == ‘2’){
res=’0’+res;
i--;
}
if(i==-1) res=’1’+res;
else{
res= (char)(str.chatAt(i)+1)+res;
res= res.substring(0,i)+res;
}
returnres;
}