10000 Merge pull request #143 from kylesliu/master · ninefive/awesome-golang-leetcode@49d5466 · GitHub
[go: up one dir, main page]

Skip to content

Commit 49d5466

Browse files
author
Kyle Liu
authored
Merge pull request 6boris#143 from kylesliu/master
sync code form master branch to develop
2 parents 81f7172 + e9eba16 commit 49d5466

File tree

56 files changed

+1047
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1047
-231
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@
110110
"contributions": [
111111
"code"
112112
]
113+
},
114+
{
115+
"login": "sathishbabu96",
116+
"name": "S Sathish Babu",
117+
"avatar_url": "https://avatars0.githubusercontent.com/u/22419483?s=400&v=4",
118+
"profile": "https://github.com/sathishbabu96",
119+
"contributions": [
120+
"code"
121+
]
113122
}
114123
]
115124
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/all-contri
5454
<!-- prettier-ignore -->
5555
| [<img src="https://avatars0.githubusercontent.com/u/26195433?v=4" width="100px;" alt="Kyle Liu "/><br /><sub><b>Kyle Liu </b></sub>](https://kyle.link)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Code") [📝](#blog-kylesliu "Blogposts") [🎨](#design-kylesliu "Design") [📖](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=kylesliu "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/34671440?v=4" width="100px;" alt="hapiman2"/><br /><sub><b>hapiman2</b></sub>](https://github.com/hapiman2)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman2 "Code") | [<img src="https://avatars0.githubusercontent.com/u/19406613?s=400&v=4" width="100px;" alt="yuechanghe"/><br /><sub><b>yuechanghe</b></sub>](https://github.com/2yuechanghe)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=2yuechanghe "Code") | [<img src="https://avatars0.githubusercontent.com/u/7567048?v=4" width="100px;" alt="hapiman"/><br /><sub><b>hapiman</b></sub>](https://github.com/hapiman)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hapiman "Code") | [<img src="https://avatars2.githubusercontent.com/u/26058740?v=4" width="100px;" alt="sihg yu"/><br /><sub><b>sihg yu</b></sub>](https://github.com/sihgyu)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=sihgyu "Code") | [<img src="https://avatars3.githubusercontent.com/u/38197795?v=4" width="100px;" alt="plusweiwei"/><br /><sub><b>plusweiwei</b></sub>](https://github.com/plusweiwei)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=plusweiwei "Code") | [<img src="https://avatars0.githubusercontent.com/u/6274967?v=4" width="100px;" alt="Sandy"/><br /><sub><b>Sandy</b></sub>](https://openset.github.com)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=openset "Code") |
5656
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
57-
| [<img src="https://avatars2.githubusercontent.com/u/23348270?s=400&v=4" width="100px;" alt="Hiep Nguyen"/><br /><sub><b>Hiep Nguyen</b></sub>](https://github.com/hiepndd)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hiepndd "Code") | [<img src="https://avatars3.githubusercontent.com/u/9403402?s=400&v=4" width="100px;" alt="mingdu"/><br /><sub><b>mingdu</b></sub>](https://github.com/dumingcode)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=dumingcode "Code") | [<img src="https://avatars0.githubusercontent.com/u/34215053?s=400&v=4" width="100px;" alt="cheng qianxiang"/><br /><sub><b>cheng qianxiang</b></sub>](https://github.com/jameschengds)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=jameschengds "Code") | [<img src="https://avatars0.githubusercontent.com/u/18567791?s=400&v=4" width="100px;" alt="Inori"/><br /><sub><b>Inori</b></sub>](https://github.com/saenaii)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=saenaii "Code") |
57+
| [<img src="https://avatars2.githubusercontent.com/u/23348270?s=400&v=4" width="100px;" alt="Hiep Nguyen"/><br /><sub><b>Hiep Nguyen</b></sub>](https://github.com/hiepndd)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=hiepndd "Code") | [<img src="https://avatars3.githubusercontent.com/u/9403402?s=400&v=4" width="100px;" alt="mingdu"/><br /><sub><b>mingdu</b></sub>](https://github.com/dumingcode)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=dumingcode "Code") | [<img src="https://avatars0.githubusercontent.com/u/34215053?s=400&v=4" width="100px;" alt="cheng qianxiang"/><br /><sub><b>cheng qianxiang</b></sub>](https://github.com/jameschengds)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=jameschengds "Code") | [<img src="https://avatars0.githubusercontent.com/u/18567791?s=400&v=4" width="100px;" alt="Inori"/><br /><sub><b>Inori</b></sub>](https://github.com/saenaii)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=saenaii "Code") | [<img src="https://avatars0.githubusercontent.com/u/22419483?s=400&v=4" width="100px;" alt="S Sathish Babu"/><br /><sub><b>S Sathish Babu</b></sub>](https://github.com/sathishbabu96)<br />[💻](https://github.com/kylesliu/awesome-golang-leetcode/commits?author=sathishbabu96 "Code") |
5858
<!-- ALL-CONTRIBUTORS-LIST:END -->
5959

6060
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

package-lock.json

Lines changed: 65 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/0086.Partition-List/ListNode.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Solution
2+
3+
type ListNode struct {
4+
Val int
5+
Next *ListNode
6+
}
7+
8+
func MakeListNode(nodes []int) *ListNode {
9+
if len(nodes) == 0 {
10+
return &ListNode{}
11+
}
12+
list := &ListNode{}
13+
head := list
14+
list.Val = nodes[0]
15+
for i := 1; i < len(nodes); i++ {
16+
list.Next = &ListNode{}
17+
list = list.Next
18+
list.Val = nodes[i]
19+
}
20+
return head
21+
}

src/0086.Partition-List/Solution.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(head *ListNode, x int) *ListNode {
4+
if head == nil || head.Next == nil {
5+
return head
6+
}
7+
before, after := &ListNode{}, &ListNode{}
8+
bh, ah := before, after
9+
for ; head != nil; head = head.Next {
10+
if head.Val < x {
11+
before.Next = head
12+
before = before.Next
13+
} else {
14+
after.Next = head
15+
after = after.Next
16+
}
17+
}
18+
after.Next, before.Next = nil, ah.Next
19+
return bh.Next
520
}

src/0086.Partition-List/Solution_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ func TestSolution(t *testing.T) {
99
// 测试用例
1010
cases := []struct {
1111
name string
12-
inputs bool
13-
expect bool
12+
head *ListNode
13+
x int
14+
expect *ListNode
1415
}{
15-
{"TestCacse 1", true, true},
16-
{"TestCacse 1", true, true},
17-
{"TestCacse 1", false, false},
16+
{"TestCase 1", MakeListNode([]int{1, 4, 3, 2, 5, 2}), 3, MakeListNode([]int{1, 2, 2, 4, 3, 5})},
17+
{"TestCase 2", MakeListNode([]int{}), 0, MakeListNode([]int{})},
18+
{"TestCase 3", MakeListNode([]int{1, 4, 3, 2, 5, 2}), 0, MakeListNode([]int{1, 4, 3, 2, 5, 2})},
1819
}
1920

2021
// 开始测试
2122
for _, c := range cases {
2223
t.Run(c.name, func(t *testing.T) {
23-
ret := Solution(c.inputs)
24+
ret := Solution(c.head, c.x)
2425
if !reflect.DeepEqual(ret, c.expect) {
25-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
26-
c.expect, ret, c.inputs)
26+
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
27+
c.expect, ret, c.head, c.x)
2728
}
2829
})
2930
}

0 commit comments

Comments
 (0)
0