Skip to content

Commit 20a0761

Browse files
committed
🐮 add some linklist problem
1 parent d0810ad commit 20a0761

File tree

13 files changed

+354
-0
lines changed

13 files changed

+354
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ LeetCode of algorithms with golang solution(updating:smiley:).
3030
| 18 | [4Sum][0018-url] | [Golang][0018-golang] | 28.5% |:purple_heart::purple_heart: |:eyes: |
3131
| 19 | [Remove Nth Node From End of List][0018-url] | [Golang][0019-golang] | 33.6% |:purple_heart: :purple_heart: | :eyes:|
3232
| 20 | [Valid Parentheses ][0020-url] | [Golang][0020-golang] | 34.7% |:purple_heart: | :eyes:|
33+
| 24 | [Swap Nodes in Pairs ][0020-url] | Golang | 41.2% |:purple_heart: :purple_heart: | :eyes:|
34+
| 25 | [Reverse Nodes in k-Group ][0020-url] | Golang | 33.6% |:purple_heart::purple_heart::purple_heart: | :eyes:|
35+
| 141 | [Linked List Cycle ][0020-url] | Golang | 34.6% |:purple_heart: | :eyes:|
36+
| 142 | [Linked List Cycle II ][0020-url] | Golang | 29.9% |:purple_heart: | :eyes:|
37+
| 206 | [Reverse Linked List ][0020-url] | Golang | 50.0% |:purple_heart: | :eyes:|
3338

3439

3540

@@ -95,3 +100,20 @@ LeetCode of algorithms with golang solution(updating:smiley:).
95100

96101
[0020-url]: https://leetcode.com/problems/valid-parentheses
97102
[0020-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0020.Valid-Parentheses
103+
104+
105+
[0024-url]: https://leetcode.com/problems/two-sum
106+
[0024-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0001.Two-Sum
107+
108+
[0025-url]: https://leetcode.com/problems/two-sum
109+
[0025-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0001.Two-Sum
110+
111+
[0141-url]: https://leetcode.com/problems/two-sum
112+
[0141-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0001.Two-Sum
113+
114+
[0142-url]: https://leetcode.com/problems/two-sum
115+
[0142-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0001.Two-Sum
116+
117+
[0206-url]: https://leetcode.com/problems/two-sum
118+
[0206-golang]: https://github.com/kylesliu/awesome-golang-leetcode/tree/master/src/0001.Two-Sum
119+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [1. Add Sum][title]
2+
3+
## Description
4+
5+
Given two binary strings, return their sum (also a binary string).
6+
7+
The input strings are both **non-empty** and contains only characters `1` or `0`.
8+
9+
**Example 1:**
10+
11+
```
12+
Input: a = "11", b = "1"
13+
Output: "100"
14+
```
15+
16+
**Example 2:**
17+
18+
```
19+
Input: a = "1010", b = "1011"
20+
Output: "10101"
21+
```
22+
23+
**Tags:** Math, String
24+
25+
## 题意
26+
>给你两个二进制串,求其和的二进制串。
27+
28+
## 题解
29+
30+
### 思路1
31+
> 按照小学算数那么来做,用 `carry` 表示进位,从后往前算,依次往前,每算出一位就插入到最前面即可,直到把两个二进制串都遍历完即可。
32+
33+
```go
34+
35+
```
36+
37+
### 思路2
38+
> 思路2
39+
```go
40+
41+
```
42+
43+
## 结语
44+
45+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]
46+
47+
[title]: https://leetcode.com/problems/two-sum/description/
48+
[me]: https://github.com/kylesliu/awesome-golang-leetcode
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Solution
2+
3+
func Solution(x bool) bool {
4+
return x
5+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSolution(t *testing.T) {
9+
// 测试用例
10+
cases := []struct {
11+
name string
12+
inputs bool
13+
expect bool
14+
}{
15+
{"TestCacse 1", true, true},
16+
{"TestCacse 1", true, true},
17+
{"TestCacse 1", false, true},
18+
}
19+
20+
// 开始测试
21+
for _, c := range cases {
22+
t.Run(c.name, func(t *testing.T) {
23+
ret := Solution(c.inputs)
24+
if !reflect.DeepEqual(ret, c.expect) {
25+
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26+
c.expect, ret, c.inputs)
27+
}
28+
})
29+
}
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [1. Add Sum][title]
2+
3+
## Description
4+
5+
Given two binary strings, return their sum (also a binary string).
6+
7+
The input strings are both **non-empty** and contains only characters `1` or `0`.
8+
9+
**Example 1:**
10+
11+
```
12+
Input: a = "11", b = "1"
13+
Output: "100"
14+
```
15+
16+
**Example 2:**
17+
18+
```
19+
Input: a = "1010", b = "1011"
20+
Output: "10101"
21+
```
22+
23+
**Tags:** Math, String
24+
25+
## 题意
26+
>给你两个二进制串,求其和的二进制串。
27+
28+
## 题解
29+
30+
### 思路1
31+
> 按照小学算数那么来做,用 `carry` 表示进位,从后往前算,依次往前,每算出一位就插入到最前面即可,直到把两个二进制串都遍历完即可。
32+
33+
```go
34+
35+
```
36+
37+
### 思路2
38+
> 思路2
39+
```go
40+
41+
```
42+
43+
## 结语
44+
45+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]
46+
47+
[title]: https://leetcode.com/problems/two-sum/description/
48+
[me]: https://github.com/kylesliu/awesome-golang-leetcode
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Solution
2+
3+
func Solution(x bool) bool {
4+
return x
5+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSolution(t *testing.T) {
9+
// 测试用例
10+
cases := []struct {
11+
name string
12+
inputs bool
13+
expect bool
14+
}{
15+
{"TestCacse 1", true, true},
16+
{"TestCacse 1", true, true},
17+
{"TestCacse 1", false, true},
18+
}
19+
20+
// 开始测试
21+
for _, c := range cases {
22+
t.Run(c.name, func(t *testing.T) {
23+
ret := Solution(c.inputs)
24+
if !reflect.DeepEqual(ret, c.expect) {
25+
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26+
c.expect, ret, c.inputs)
27+
}
28+
})
29+
}
30+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# [1. Add Sum][title]
2+
3+
## Description
4+
5+
Given two binary strings, return their sum (also a binary string).
6+
7+
The input strings are both **non-empty** and contains only characters `1` or `0`.
8+
9+
**Example 1:**
10+
11+
```
12+
Input: a = "11", b = "1"
13+
Output: "100"
14+
```
15+
16+
**Example 2:**
17+
18+
```
19+
Input: a = "1010", b = "1011"
20+
Output: "10101"
21+
```
22+
23+
**Tags:** Math, String
24+
25+
## 题意
26+
>给你两个二进制串,求其和的二进制串。
27+
28+
## 题解
29+
30+
### 思路1
31+
> 按照小学算数那么来做,用 `carry` 表示进位,从后往前算,依次往前,每算出一位就插入到最前面即可,直到把两个二进制串都遍历完即可。
32+
33+
```go
34+
35+
```
36+
37+
### 思路2
38+
> 思路2
39+
```go
40+
41+
```
42+
43+
## 结语
44+
45+
如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:[awesome-golang-leetcode][me]
46+
47+
[title]: https://leetcode.com/problems/two-sum/description/
48+
[me]: https://github.com/kylesliu/awesome-golang-leetcode
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package Solution
2+
3+
func Solution(x bool) bool {
4+
return x
5+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package Solution
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func TestSolution(t *testing.T) {
9+
// 测试用例
10+
cases := []struct {
11+
name string
12+
inputs bool
13+
expect bool
14+
}{
15+
{"TestCacse 1", true, true},
16+
{"TestCacse 1", true, true},
17+
{"TestCacse 1", false, true},
18+
}
19+
20+
// 开始测试
21+
for _, c := range cases {
22+
t.Run(c.name, func(t *testing.T) {
23+
ret := Solution(c.inputs)
24+
if !reflect.DeepEqual(ret, c.expect) {
25+
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26+
c.expect, ret, c.inputs)
27+
}
28+
})
29+
}
30+
}

0 commit comments

Comments
 (0)