Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c09563d

Browse files
committed
commit solution 3
1 parent f5c845b commit c09563d

File tree

5 files changed

+110
-2
lines changed

5 files changed

+110
-2
lines changed

‎index-tags.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
| 题号 | 题解 | 标签 | 难度 | 是否解题 |
4040
| --- | --- | --- | --- | --- |
41+
| [3](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | [无重复字符的最长子串](/solution/1-99/0003.longest-substring-without-repeating-characters/) | `哈希表`,`双指针`,`字符串` | <font color=blue>中等</font> ||
4142
| [13](https://leetcode-cn.com/problems/roman-to-integer) | [罗马数字转整数](/solution/1-99/0013.roman-to-integer/) | `数学`,`字符串` | <font color=green>简单</font> ||
4243
| [14](https://leetcode-cn.com/problems/longest-common-prefix) | [最长公共前缀](/solution/1-99/0014.longest-common-prefix/) | `字符串` | <font color=green>简单</font> ||
4344
| [20](https://leetcode-cn.com/problems/valid-parentheses) | [有效的括号](/solution/1-99/0020.valid-parentheses/) | ``,`字符串` | <font color=green>简单</font> ||
@@ -70,6 +71,7 @@
7071
| 题号 | 题解 | 标签 | 难度 | 是否解题 |
7172
| --- | --- | --- | --- | --- |
7273
| [1](https://leetcode-cn.com/problems/two-sum) | [两数之和](/solution/1-99/0001.two-sum/) | `数组`,`哈希表` | <font color=green>简单</font> ||
74+
| [3](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | [无重复字符的最长子串](/solution/1-99/0003.longest-substring-without-repeating-characters/) | `哈希表`,`双指针`,`字符串` | <font color=blue>中等</font> ||
7375
| [36](https://leetcode-cn.com/problems/valid-sudoku) | [有效的数独](/solution/1-99/0036.valid-sudoku/) | `哈希表` | <font color=blue>中等</font> ||
7476
| [49](https://leetcode-cn.com/problems/group-anagrams) | [字母异位词分组](/solution/1-99/0049.group-anagrams/) | `哈希表`,`字符串` | <font color=blue>中等</font> ||
7577
| [136](https://leetcode-cn.com/problems/single-number) | [只出现一次的数字](/solution/100-199/0136.single-number/) | `位运算`,`哈希表` | <font color=green>简单</font> ||
@@ -97,6 +99,7 @@
9799

98100
| 题号 | 题解 | 标签 | 难度 | 是否解题 |
99101
| --- | --- | --- | --- | --- |
102+
| [3](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | [无重复字符的最长子串](/solution/1-99/0003.longest-substring-without-repeating-characters/) | `哈希表`,`双指针`,`字符串` | <font color=blue>中等</font> ||
100103
| [11](https://leetcode-cn.com/problems/container-with-most-water) | [盛最多水的容器](/solution/1-99/0011.container-with-most-water/) | `数组`,`双指针` | <font color=blue>中等</font> ||
101104
| [15](https://leetcode-cn.com/problems/3sum) | [三数之和](/solution/1-99/0015.3sum/) | `数组`,`双指针` | <font color=blue>中等</font> ||
102105
| [26](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | [删除排序数组中的重复项](/solution/1-99/0026.remove-duplicates-from-sorted-array/) | `数组`,`双指针` | <font color=green>简单</font> ||

‎index-type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@
406406
| 题号 | 题解 | 标签 | 难度 | 是否解题 |
407407
| --- | --- | --- | --- | --- |
408408
| [2](https://leetcode-cn.com/problems/add-two-numbers) | [两数相加](/solution/1-99/0002.add-two-numbers/) | `链表`,`数学` | <font color=blue>中等</font> ||
409-
| [3](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | [无重复字符的最长子串](/solution/1-99/0003.longest-substring-without-repeating-characters/) | `哈希表`,`双指针`,`字符串` | <font color=blue>中等</font> |
409+
| [3](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | [无重复字符的最长子串](/solution/1-99/0003.longest-substring-without-repeating-characters/) | `哈希表`,`双指针`,`字符串` | <font color=blue>中等</font> ||
410410
| [5](https://leetcode-cn.com/problems/longest-palindromic-substring) | [最长回文子串](/solution/1-99/0005.longest-palindromic-substring/) | `字符串`,`动态规划` | <font color=blue>中等</font> |
411411
| [6](https://leetcode-cn.com/problems/zigzag-conversion) | [z 字形变换](/solution/1-99/0006.zigzag-conversion/) | `字符串` | <font color=blue>中等</font> |
412412
| [8](https://leetcode-cn.com/problems/string-to-integer-atoi) | [字符串转换整数 (atoi)](/solution/1-99/0008.string-to-integer-%28atoi%29/) | `数学`,`字符串` | <font color=blue>中等</font> |

‎solution/1-99/0003.longest-substring-without-repeating-characters/README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,53 @@
3333

3434
### 具体解法
3535

36+
<!-- tabs:start -->
3637

37-
#### **Golang**
38+
#### **Golang1**
3839
```go
40+
func lengthOfLongestSubstring1(s string) int {
41+
var res int
42+
for i := range s {
43+
sMap := make(map[byte]bool)
44+
q := 0
45+
for q+i < len(s) {
46+
if sMap[s[q+i]] {
47+
break
48+
} else {
49+
sMap[s[q+i]] = true
50+
}
51+
q++
52+
}
53+
if q > res {
54+
res = q
55+
}
56+
if q >= len(s)-i {
57+
break
58+
}
59+
}
60+
return res
61+
}
62+
```
3963

64+
#### **Golang2**
65+
```go
66+
func lengthOfLongestSubstring(s string) int {
67+
m, max, left := make(map[rune]int), 0, 0
68+
for idx, c := range s {
69+
if _, okay := m[c]; okay == true && m[c] >= left {
70+
if idx-left > max {
71+
max = idx - left
72+
}
73+
left = m[c] + 1
74+
}
75+
m[c] = idx
76+
}
77+
if len(s)-left > max {
78+
max = len(s) - left
79+
}
80+
return max
81+
}
4082
```
83+
84+
<!-- tabs:end -->
85+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package leetcode
2+
3+
/*
4+
* @lc app=leetcode.cn id=3 lang=golang
5+
*
6+
* [3] 无重复字符的最长子串
7+
*/
8+
9+
// @lc code=start
10+
func lengthOfLongestSubstring1(s string) int {
11+
var res int
12+
for i := range s {
13+
sMap := make(map[byte]bool)
14+
q := 0
15+
for q+i < len(s) {
16+
if sMap[s[q+i]] {
17+
break
18+
} else {
19+
sMap[s[q+i]] = true
20+
}
21+
q++
22+
}
23+
if q > res {
24+
res = q
25+
}
26+
if q >= len(s)-i {
27+
break
28+
}
29+
}
30+
return res
31+
}
32+
33+
// @lc code=end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package leetcode
2+
3+
/*
4+
* @lc app=leetcode.cn id=3 lang=golang
5+
*
6+
* [3] 无重复字符的最长子串
7+
*/
8+
9+
// @lc code=start
10+
func lengthOfLongestSubstring(s string) int {
11+
m, max, left := make(map[rune]int), 0, 0
12+
for idx, c := range s {
13+
if _, okay := m[c]; okay == true && m[c] >= left {
14+
if idx-left > max {
15+
max = idx - left
16+
}
17+
left = m[c] + 1
18+
}
19+
m[c] = idx
20+
}
21+
if len(s)-left > max {
22+
max = len(s) - left
23+
}
24+
return max
25+
}
26+
27+
// @lc code=end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /