We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 63d1ff3 commit 53e69efCopy full SHA for 53e69ef
.gitignore
@@ -4,3 +4,4 @@
4
.mvn/*
5
target
6
*.class
7
+*.iml
src/main/java/com/fibers/algorithm/leetcode/_003/Solution.java
@@ -1,4 +1,21 @@
1
package com.fibers.algorithm.leetcode._003;
2
3
+import java.util.HashMap;
+
public class Solution {
+ public int lengthOfLongestSubstring(String s) {
+ if (s.length() == 0) {
8
+ return 0;
9
+ }
10
+ HashMap<Character, Integer> map = new HashMap<>();
11
+ int max = 0;
12
+ for (int i = 0, j = 0; i < s.length(); ++i) {
13
+ if (map.containsKey(s.charAt(i))) {
14
+ j = Math.max(j, map.get(s.charAt(i)) + 1);
15
16
+ map.put(s.charAt(i), i);
17
+ max = Math.max(max, i - j + 1);
18
19
+ return max;
20
21
}
0 commit comments