mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-20 05:33:53 +08:00
Add weekly-contest-214
This commit is contained in:
@ -0,0 +1,21 @@
|
||||
package leetcode
|
||||
|
||||
func getMaximumGenerated(n int) int {
|
||||
if n == 0 {
|
||||
return 0
|
||||
}
|
||||
nums, max := make([]int, n+1), 0
|
||||
nums[0], nums[1] = 0, 1
|
||||
for i := 0; i <= n; i++ {
|
||||
if nums[i] > max {
|
||||
max = nums[i]
|
||||
}
|
||||
if 2*i >= 2 && 2*i <= n {
|
||||
nums[2*i] = nums[i]
|
||||
}
|
||||
if 2*i+1 >= 2 && 2*i+1 <= n {
|
||||
nums[2*i+1] = nums[i] + nums[i+1]
|
||||
}
|
||||
}
|
||||
return max
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package leetcode
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type question5561 struct {
|
||||
para5561
|
||||
ans5561
|
||||
}
|
||||
|
||||
// para 是参数
|
||||
// one 代表第一个参数
|
||||
type para5561 struct {
|
||||
n int
|
||||
}
|
||||
|
||||
// ans 是答案
|
||||
// one 代表第一个答案
|
||||
type ans5561 struct {
|
||||
one int
|
||||
}
|
||||
|
||||
func Test_Problem5561(t *testing.T) {
|
||||
|
||||
qs := []question5561{
|
||||
|
||||
{
|
||||
para5561{7},
|
||||
ans5561{3},
|
||||
},
|
||||
|
||||
{
|
||||
para5561{2},
|
||||
ans5561{1},
|
||||
},
|
||||
|
||||
{
|
||||
para5561{3},
|
||||
ans5561{2},
|
||||
},
|
||||
|
||||
{
|
||||
para5561{0},
|
||||
ans5561{0},
|
||||
},
|
||||
|
||||
{
|
||||
para5561{1},
|
||||
ans5561{1},
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Printf("------------------------Leetcode Problem 5561------------------------\n")
|
||||
|
||||
for _, q := range qs {
|
||||
_, p := q.ans5561, q.para5561
|
||||
fmt.Printf("【input】:%v 【output】:%v \n", p, getMaximumGenerated(p.n))
|
||||
}
|
||||
fmt.Printf("\n\n\n")
|
||||
}
|
Reference in New Issue
Block a user