We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cad42ee commit fc91870Copy full SHA for fc91870
solution/0003.Longest Substring Without Repeating Characters/Solution.go
@@ -0,0 +1,22 @@
1
+/*
2
+ * Report by leetcode.com
3
+ * Runtime: 8 ms, Memory Usage: 3.2 MB
4
+ */
5
+func lengthOfLongestSubstring(s string) int {
6
+ mathMax := func(a, b int) int {
7
+ if a > b {
8
+ return a
9
+ }
10
+ return b
11
12
+ cache := map[rune]int{}
13
+ var max, position int
14
+ for i, r := range s {
15
+ if num, ok := cache[r]; ok {
16
+ position = mathMax(position, num+1)
17
18
+ cache[r] = i
19
+ max = mathMax(max, i-position+1)
20
21
+ return max
22
+}
0 commit comments