Skip to content

Commit b77d1bb

Browse files
committed
[E:75/537, M:71/980, H:9/391] add No: 1000023: The Masseuse LCCI
1 parent ed0e3ba commit b77d1bb

File tree

9 files changed

+319
-0
lines changed

9 files changed

+319
-0
lines changed

.leetcode.db

0 Bytes
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## [按摩师](https://leetcode-cn.com/problems/the-masseuse-lcci/)
2+
3+
一个有名的按摩师会收到源源不断的预约请求,每个预约都可以选择接或不接。在每次预约服务之间要有休息时间,因此她不能接受相邻的预约。给定一个预约请求序列,替按摩师找到最优的预约集合(总预约时间最长),返回总的分钟数。
4+
5+
**注意:**本题相对原题稍作改动
6+
7+
 
8+
9+
**示例 1:**
10+
11+
`**输入:** [1,2,3,1]
12+
**输出:** 4
13+
**解释:** 选择 1 号预约和 3 号预约,总时长 = 1 + 3 = 4。
14+
`
15+
16+
**示例 2:**
17+
18+
`**输入:** [2,7,9,3,1]
19+
**输出:** 12
20+
**解释:** 选择 1 号预约、 3 号预约和 5 号预约,总时长 = 2 + 9 + 1 = 12。
21+
`
22+
23+
**示例 3:**
24+
25+
`**输入:** [2,1,4,5,3,1,1,3]
26+
**输出:** 12
27+
**解释:** 选择 1 号预约、 3 号预约、 5 号预约和 8 号预约,总时长 = 2 + 4 + 3 + 3 = 12。
28+
`
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"reflect"
7+
"time"
8+
9+
"github.com/gladmo/leetcode/leet"
10+
"github.com/gladmo/leetcode/questions/serial/easy/1000023/golang/solution"
11+
)
12+
13+
func main() {
14+
tests := []struct {
15+
name string
16+
input []int
17+
want int
18+
}{
19+
{
20+
name: "test-[1,3,1]",
21+
input: []int{1, 3, 1},
22+
want: 3,
23+
},
24+
{
25+
name: "test-[1,2,3,1]",
26+
input: []int{1, 2, 3, 1},
27+
want: 4,
28+
},
29+
{
30+
name: "test-[2,1,4,5,3,1,1,3]",
31+
input: []int{2, 1, 4, 5, 3, 1, 1, 3},
32+
want: 12,
33+
},
34+
{
35+
name: "test-[2,7,9,3,1]",
36+
input: []int{2, 7, 9, 3, 1},
37+
want: 12,
38+
},
39+
{
40+
name: "test-[2]",
41+
input: []int{2},
42+
want: 2,
43+
},
44+
{
45+
name: "test-[2,7]",
46+
input: []int{2, 7},
47+
want: 7,
48+
},
49+
{
50+
name: "test-[]",
51+
input: []int{},
52+
want: 0,
53+
},
54+
}
55+
56+
testLog := leet.NewTestLog(len(tests))
57+
defer testLog.Render()
58+
59+
timeoutDuration := time.Second * 2
60+
61+
for idx, test := range tests {
62+
// 超时检测
63+
got := test.want
64+
timeout := leet.Timeout(timeoutDuration, func(ctx context.Context, cancel context.CancelFunc) {
65+
got = solution.Export(test.input)
66+
cancel()
67+
})
68+
69+
if timeout {
70+
testLog.Fail(idx+1, test.name, "timeout")
71+
continue
72+
}
73+
74+
if !reflect.DeepEqual(test.want, got) {
75+
testLog.Fail(idx+1, test.name, fmt.Sprintf("want: %v, got %v.", test.want, got))
76+
continue
77+
}
78+
79+
testLog.Pass(idx+1, test.name)
80+
}
81+
}

questions/serial/easy/1000023/golang/solution/the-masseuse-lcci.go

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+
"fmt"
5+
"os"
6+
"runtime/debug"
7+
)
8+
9+
func Export(nums []int) int { defer func() {
10+
if r := recover(); r != nil {
11+
fmt.Println("Params: ", nums)
12+
fmt.Println("Panic:", r)
13+
fmt.Println()
14+
debug.PrintStack()
15+
os.Exit(0)
16+
}
17+
}()
18+
19+
return massage(nums)
20+
21+
}
22+
23+
/****************************************************/
24+
/******** 以下为 Leetcode 示例部分(提交PR请还原) *******/
25+
/******** 使用 (./leetcode clear) 初始化所有问题 *******/
26+
/****************************************************/
27+
28+
func massage(nums []int) int {
29+
30+
}

questions/serial/easy/1000023/golang/solution/the-masseuse-lcci.go.clean

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+
"fmt"
5+
"os"
6+
"runtime/debug"
7+
)
8+
9+
func Export(nums []int) int { defer func() {
10+
if r := recover(); r != nil {
11+
fmt.Println("Params: ", nums)
12+
fmt.Println("Panic:", r)
13+
fmt.Println()
14+
debug.PrintStack()
15+
os.Exit(0)
16+
}
17+
}()
18+
19+
return massage(nums)
20+
21+
}
22+
23+
/****************************************************/
24+
/******** 以下为 Leetcode 示例部分(提交PR请还原) *******/
25+
/******** 使用 (./leetcode clear) 初始化所有问题 *******/
26+
/****************************************************/
27+
28+
func massage(nums []int) int {
29+
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## [按摩师](https://leetcode-cn.com/problems/the-masseuse-lcci/)
2+
3+
一个有名的按摩师会收到源源不断的预约请求,每个预约都可以选择接或不接。在每次预约服务之间要有休息时间,因此她不能接受相邻的预约。给定一个预约请求序列,替按摩师找到最优的预约集合(总预约时间最长),返回总的分钟数。
4+
5+
**注意:**本题相对原题稍作改动
6+
7+
 
8+
9+
**示例 1:**
10+
11+
`**输入:** [1,2,3,1]
12+
**输出:** 4
13+
**解释:** 选择 1 号预约和 3 号预约,总时长 = 1 + 3 = 4。
14+
`
15+
16+
**示例 2:**
17+
18+
`**输入:** [2,7,9,3,1]
19+
**输出:** 12
20+
**解释:** 选择 1 号预约、 3 号预约和 5 号预约,总时长 = 2 + 9 + 1 = 12。
21+
`
22+
23+
**示例 3:**
24+
25+
`**输入:** [2,1,4,5,3,1,1,3]
26+
**输出:** 12
27+
**解释:** 选择 1 号预约、 3 号预约、 5 号预约和 8 号预约,总时长 = 2 + 4 + 3 + 3 = 12。
28+
`
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"reflect"
7+
"time"
8+
9+
"github.com/gladmo/leetcode/questions/tags/动态规划/easy/the-masseuse-lcci/golang/solution"
10+
"github.com/gladmo/leetcode/leet"
11+
)
12+
13+
func main() {
14+
/*
15+
16+
[1,2,3,1]
17+
18+
*/
19+
20+
tests := []struct {
21+
name string
22+
input [][]int
23+
want bool
24+
}{
25+
{
26+
name: "test-[[1],[2],[3],[]]",
27+
input: [][]int{
28+
{1},
29+
{2},
30+
{3},
31+
{},
32+
},
33+
want: true,
34+
},
35+
}
36+
37+
testLog := leet.NewTestLog(len(tests))
38+
defer testLog.Render()
39+
40+
timeoutDuration := time.Second * 2
41+
42+
for idx, test := range tests {
43+
// 超时检测
44+
got := test.want
45+
timeout := leet.Timeout(timeoutDuration, func(ctx context.Context, cancel context.CancelFunc) {
46+
got = solution.Export(test.input)
47+
cancel()
48+
})
49+
50+
if timeout {
51+
testLog.Fail(idx+1, test.name, "timeout")
52+
continue
53+
}
54+
55+
if !reflect.DeepEqual(test.want, got) {
56+
testLog.Fail(idx+1, test.name, fmt.Sprintf("want: %v, got %v.", test.want, got))
57+
continue
58+
}
59+
60+
testLog.Pass(idx+1, test.name)
61+
}
62+
}

questions/tags/动态规划/easy/the-masseuse-lcci/golang/solution/the-masseuse-lcci.go

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+
"fmt"
5+
"os"
6+
"runtime/debug"
7+
)
8+
9+
func Export(nums []int) int { defer func() {
10+
if r := recover(); r != nil {
11+
fmt.Println("Params: ", nums)
12+
fmt.Println("Panic:", r)
13+
fmt.Println()
14+
debug.PrintStack()
15+
os.Exit(0)
16+
}
17+
}()
18+
19+
return massage(nums)
20+
21+
}
22+
23+
/****************************************************/
24+
/******** 以下为 Leetcode 示例部分(提交PR请还原) *******/
25+
/******** 使用 (./leetcode clear) 初始化所有问题 *******/
26+
/****************************************************/
27+
28+
func massage(nums []int) int {
29+
30+
}

questions/tags/动态规划/easy/the-masseuse-lcci/golang/solution/the-masseuse-lcci.go.clean

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+
"fmt"
5+
"os"
6+
"runtime/debug"
7+
)
8+
9+
func Export(nums []int) int { defer func() {
10+
if r := recover(); r != nil {
11+
fmt.Println("Params: ", nums)
12+
fmt.Println("Panic:", r)
13+
fmt.Println()
14+
debug.PrintStack()
15+
os.Exit(0)
16+
}
17+
}()
18+
19+
return massage(nums)
20+
21+
}
22+
23+
/****************************************************/
24+
/******** 以下为 Leetcode 示例部分(提交PR请还原) *******/
25+
/******** 使用 (./leetcode clear) 初始化所有问题 *******/
26+
/****************************************************/
27+
28+
func massage(nums []int) int {
29+
30+
}

0 commit comments

Comments
 (0)