From a6a31420ec67e3ea2030d0074c37b266e896b90f Mon Sep 17 00:00:00 2001 From: Cookie <398212699@qq.com> Date: Mon, 18 Nov 2019 20:00:56 +0800 Subject: [PATCH 1/2] replace HashSet with LinkedHashSet --- .../github/hcsp/collection/RemoveDuplicateCharsInString.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java b/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java index cae1919..b40283a 100644 --- a/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java +++ b/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java @@ -8,7 +8,7 @@ public class RemoveDuplicateCharsInString { // 输入ccbbaa返回cba // 输入apple返回aple public static String removeDuplicateCharsInString(String s) { - HashSet charSet = new HashSet<>(); + HashSet charSet = new LinkedHashSet<>(); for (int i = 0; i < s.length(); i++) { charSet.add(s.charAt(i)); } From fda21695b6b984c43da6e7a713b58e5cd7749170 Mon Sep 17 00:00:00 2001 From: Cookie <398212699@qq.com> Date: Mon, 18 Nov 2019 20:01:24 +0800 Subject: [PATCH 2/2] import java.util.LinkedHashSet --- .../com/github/hcsp/collection/RemoveDuplicateCharsInString.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java b/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java index b40283a..92ff7d1 100644 --- a/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java +++ b/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java @@ -1,6 +1,7 @@ package com.github.hcsp.collection; import java.util.HashSet; +import java.util.LinkedHashSet; public class RemoveDuplicateCharsInString { // 修改这个方法使得它能够输出正确结果: