|
|
@@ -154,6 +154,7 @@ counter++;
|
|
154
|
154
|
public static String[] removeConsecutiveDuplicates(String[] array) {
|
|
155
|
155
|
String[] tempArr = new String[array.length];
|
|
156
|
156
|
int counter = 0;
|
|
|
157
|
+ int decrement = 0;
|
|
157
|
158
|
for (int i=0; i<array.length-1; i++){
|
|
158
|
159
|
if (array[i].equals(array[i+1])){
|
|
159
|
160
|
continue;
|
|
|
@@ -162,9 +163,15 @@ counter++;
|
|
162
|
163
|
}
|
|
163
|
164
|
// int decrement = tempArr.indexOf(null);
|
|
164
|
165
|
}
|
|
165
|
|
-
|
|
166
|
|
- System.out.print(tempArr);
|
|
167
|
|
-return array;
|
|
|
166
|
+ for (int i=0; i<tempArr.length; i++){
|
|
|
167
|
+ if (tempArr[i] == null)
|
|
|
168
|
+ { decrement = i;
|
|
|
169
|
+ break;}
|
|
|
170
|
+ }
|
|
|
171
|
+ String[] resultArr= Arrays.copyOf(tempArr, decrement+1);
|
|
|
172
|
+ resultArr[resultArr.length-1] = array[array.length-1];
|
|
|
173
|
+ System.out.print(resultArr);
|
|
|
174
|
+return resultArr;
|
|
168
|
175
|
}
|
|
169
|
176
|
|
|
170
|
177
|
/**
|
|
|
@@ -172,7 +179,34 @@ return array;
|
|
172
|
179
|
* @return array of Strings with each consecutive duplicate occurrence concatenated as a single string in an array of Strings
|
|
173
|
180
|
*/ // TODO
|
|
174
|
181
|
public static String[] packConsecutiveDuplicates(String[] array) {
|
|
175
|
|
- return null;
|
|
|
182
|
+
|
|
|
183
|
+ String[] tempArr = new String[array.length];
|
|
|
184
|
+ String tempString = "";
|
|
|
185
|
+ int counter = 0;
|
|
|
186
|
+ int decrement = 0;
|
|
|
187
|
+ for (int i=0; i<array.length-1; i++){
|
|
|
188
|
+ if (array[i].equals(array[i+1])){
|
|
|
189
|
+ tempString = array[i] + array[i];
|
|
|
190
|
+ continue;
|
|
|
191
|
+ } else if (array[i].equals(array[i+1])){
|
|
|
192
|
+ tempArr[counter++] = tempString;
|
|
|
193
|
+ continue;
|
|
|
194
|
+ }
|
|
|
195
|
+ else{
|
|
|
196
|
+ tempArr[counter++]=array[i];
|
|
|
197
|
+ }
|
|
|
198
|
+
|
|
|
199
|
+ }
|
|
|
200
|
+ for (int i=0; i<tempArr.length; i++){
|
|
|
201
|
+ if (tempArr[i] == null)
|
|
|
202
|
+ { decrement = i;
|
|
|
203
|
+ break;}
|
|
|
204
|
+ }
|
|
|
205
|
+ String[] resultArr= Arrays.copyOf(tempArr, decrement+1);
|
|
|
206
|
+ resultArr[resultArr.length-1] = array[array.length-1];
|
|
|
207
|
+ System.out.print(resultArr);
|
|
|
208
|
+ return resultArr;
|
|
|
209
|
+
|
|
176
|
210
|
}
|
|
177
|
211
|
|
|
178
|
212
|
|