|
|
@@ -0,0 +1,39 @@
|
|
|
+package main
|
|
|
+
|
|
|
+import "fmt"
|
|
|
+
|
|
|
+
|
|
|
+// Runtime: 360ms Unstable Ram: 24.44mb
|
|
|
+func lengthOfLongestSubstring(s string) int {
|
|
|
+ var m map[uint8]int = make(map[uint8]int)
|
|
|
+ var i int = 0
|
|
|
+ var c uint8 = 0
|
|
|
+ var max int = 0
|
|
|
+
|
|
|
+ if len(s) <= 1 {
|
|
|
+ return len(s)
|
|
|
+ }
|
|
|
+
|
|
|
+ for ; i < len(s); i++ {
|
|
|
+ c = s[i]
|
|
|
+ if _i, ok := m[c]; ok {
|
|
|
+ if len(m) > max {
|
|
|
+ max = len(m)
|
|
|
+ }
|
|
|
+ m = make(map[uint8]int)
|
|
|
+ i = _i
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ m[c] = i
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(m) > max {
|
|
|
+ max = len(m)
|
|
|
+ }
|
|
|
+
|
|
|
+ return max
|
|
|
+}
|
|
|
+
|
|
|
+func main() {
|
|
|
+ fmt.Printf("%v\n", lengthOfLongestSubstring("dvdf"))
|
|
|
+}
|