From e87aebda392e89bfd94c1df1aa5e6f337edb726e Mon Sep 17 00:00:00 2001 From: wangsiyuan <2392948297@qq.com> Date: Tue, 5 Sep 2023 00:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=20Solution.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/solution/Solution.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/solution/Solution.java diff --git a/src/solution/Solution.java b/src/solution/Solution.java new file mode 100644 index 0000000..cfbaae7 --- /dev/null +++ b/src/solution/Solution.java @@ -0,0 +1,17 @@ +package solution; + +import java.util.HashSet; +import java.util.Set; + +public class Solution { + public int lengthOfLongestSubstring(String s) { + if (s != null){ + Set stringList = new HashSet<>(); + for (int i = 0; i < s.length(); i++) { + stringList.add(s.charAt(i)); + } + return stringList.size(); + } + return 0; + } +}