File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package datastructure .string ;
2
+
3
+ /**
4
+ * Minimize the string
5
+ * @author Manjunath Asundi
6
+ */
7
+ public class EncryptString {
8
+
9
+ public static String encryptStringUtil (String string ) {
10
+ StringBuilder encryptedString = new StringBuilder ();
11
+ int j ;
12
+ for (int i = 0 ; i < string .length (); i = j ) {
13
+ j = i + 1 ;
14
+ while (j < string .length () && string .charAt (i ) == string .charAt (j ))
15
+ j ++;
16
+ if ((j - i ) > 1 )
17
+ encryptedString .append ("" + (j - i ) + string .charAt (i ));
18
+ else
19
+ encryptedString .append ("" + string .charAt (i ));
20
+ }
21
+ return encryptedString .toString ();
22
+ }
23
+
24
+ public static void main (String [] args ) {
25
+ String string = "aaaaaaaaaabbbcccbbaaabc" ;
26
+ System .out .println ("Input String: " + string );
27
+ System .out .println ("Output String: " + encryptStringUtil (string ));
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments