Browse Source

final changes

Elliott Stansbury 5 years ago
parent
commit
ae8bc68f8f
1 changed files with 7 additions and 6 deletions
  1. 7
    6
      src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java

+ 7
- 6
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java View File

@@ -73,17 +73,18 @@ public class StringUtils {
73 73
 
74 74
         StringBuilder builder = new StringBuilder();
75 75
 
76
+        char previous = 'k';
77
+        int counter = 0;
78
+
76 79
         char arr[] = str.toCharArray();
77 80
 
78 81
         for(int i = 0; i < arr.length; i++){
79
-                if(arr[i] != arr[j]){
80
-                    builder.append(arr[i]);
82
+                if(previous != arr[i]){
83
+                    arr[counter++] = arr[i];
84
+                    previous = arr[i];
81 85
                 }
82 86
             }
83
-
84
-
85
-
86
-        return builder.toString();
87
+        return new String(arr).substring(0,counter);
87 88
     }
88 89
 
89 90
     public static String invertCasing(String str) {