- Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRunLength.java
32 lines (27 loc) · 649 Bytes
/
RunLength.java
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
importjava.util.;
importjava.io.;
classMain {
publicstaticStringRunLength(Stringstr) {
// code goes here
Stringrepost = "";
intcount = 1;
charc = str.charAt(0);
for(inti=1; i<str.length();i++){
if(str.charAt(i)==c){
count++;
}
else{
repost += count + "" +c;
c = str.charAt(i);
count = 1;
}
}
repost += count + "" +c;
returnrepost;
}
publicstaticvoidmain (String[] args) {
// keep this function call here
Scanners = newScanner(System.in);
System.out.print(RunLength(s.nextLine()));
}
}