From 04ba2fef6a88ac1a5eccb79753c361e384a6aea2 Mon Sep 17 00:00:00 2001 From: zaker-666 <1075151259china@gmail.com> Date: Mon, 6 Jan 2020 23:07:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/hcsp/collection/RemoveDuplicateCharsInString.java | 4 +++- 1 file changed, 3 insertions(+), 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..68e2f07 100644 --- a/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java +++ b/src/main/java/com/github/hcsp/collection/RemoveDuplicateCharsInString.java @@ -1,6 +1,8 @@ package com.github.hcsp.collection; import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; public class RemoveDuplicateCharsInString { // 修改这个方法使得它能够输出正确结果: @@ -8,7 +10,7 @@ public class RemoveDuplicateCharsInString { // 输入ccbbaa返回cba // 输入apple返回aple public static String removeDuplicateCharsInString(String s) { - HashSet charSet = new HashSet<>(); + Set charSet = new LinkedHashSet<>(); for (int i = 0; i < s.length(); i++) { charSet.add(s.charAt(i)); }