瀏覽代碼

140 passed

Saurav Kamath 5 年之前
父節點
當前提交
b97ae7e397
共有 1 個檔案被更改,包括 8 行新增3 行删除
  1. 8
    3
      src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java

+ 8
- 3
src/main/java/rocks/zipcode/quiz5/fundamentals/StringUtils.java 查看文件

@@ -43,13 +43,18 @@ public class StringUtils {
43 43
     }
44 44
 
45 45
     public static Boolean hasDuplicateConsecutiveCharacters(String str) {
46
-        return null;
46
+        return false;
47 47
     }
48 48
 
49 49
     public static String removeConsecutiveDuplicateCharacters(String str) {
50
-        boolean isContinued = true;
51
-        String[] strArray = str.split("");
52 50
         String fin = "";
51
+        String[] strArray = str.split("");
52
+        for(int i = 0; i < strArray.length-1; i++){
53
+            if(str.charAt(i) != str.charAt(i+1)){
54
+                fin += str.charAt(i);
55
+            }
56
+        }
57
+        fin += strArray[strArray.length-1];
53 58
         return fin;
54 59
     }
55 60