Skip to content

Commit

Permalink
feat:add 百度面经
Browse files Browse the repository at this point in the history
  • Loading branch information
mao888 committed Aug 29, 2024
1 parent 640c670 commit 01b10ee
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@ package main

import "fmt"

//type ListNode struct {
// Val int
// Next *ListNode
//}
//一个n米深的井,每分钟只能爬u米,每次爬之前都要休息一分钟,休息期间会下滑d米,求爬出井需要多少分钟?
//输入n,u,d,输出所需分钟

//type TreeNode struct {
// Val int
// Left *TreeNode
// Right *TreeNode
//}
// 构建一个示例二叉树
// 1
// / \
// 2 3
// /| |\
// 4 5 6 7
//root := &TreeNode{Val: 1}
//root.Left = &TreeNode{Val: 2}
//root.Right = &TreeNode{Val: 3}
//root.Left.Left = &TreeNode{Val: 4}
//root.Left.Right = &TreeNode{Val: 5}
//root.Right.Left = &TreeNode{Val: 6}
//root.Right.Right = &TreeNode{Val: 7}
func minute(n, u, d int) int {
// 爬升净值
netClimb := u - d
if n <= u {
return 1
}
// 除最后一次爬升的循环次数
cycles := n/netClimb - 1
// 总时长:每次循环 2 分钟,加上最后一次爬升1分钟
total := cycles*2 + 1
return total
}

func main() {
fmt.Println("Hello World!")
n := 10
u := 2
d := 1
fmt.Println(minute(n, u, d))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import "fmt"

type ListNode struct {
Val int
Next *ListNode
}

func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode {
dummy := &ListNode{}

current := dummy

for l1 != nil && l2 != nil {
if l1.Val <= l2.Val {
current.Next = l1
l1 = l1.Next
} else {
current.Next = l2
l2 = l2.Next
}
current = current.Next
}

if l1 != nil {
current.Next = l1
} else if l2 != nil {
current.Next = l2
}
return dummy.Next
}

func main() {
fmt.Println("Hello World!")
}

0 comments on commit 01b10ee

Please sign in to comment.