From 127b98c8610d1da6f09c6bf3bb603e033b2d19fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cidpeng=E2=80=9D?= <630606938@qq.com> Date: Tue, 14 Sep 2021 11:31:06 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8LinkedHashSet=E4=BF=9D=E8=AF=81?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/hcsp/collection/RemoveDuplicateCharsInString.java | 3 ++- 1 file changed, 2 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..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 { // 修改这个方法使得它能够输出正确结果: @@ -8,7 +9,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)); }