摘要:
//一使用一个中间数组 func merge(nums1 []int, m int, nums2 []int, n int) { tmp:=make([]int,n+m) copy(tmp,nums1)//深拷贝 i:=0;j:=0;k:=0 for i<m&&j<n{ if tmp[i]>nums 阅读全文
摘要:
给定一个二叉树, 找到该树中两个指定节点间的最短距离 // A// B C//D E F// D E --> 2// E F --> 4解法一:先求两节点的最近公共祖先,然后层序遍历求三个节点所在位置的深度,然后距离加减就行 func main() { //按数组层序建立二叉树 root:=crea 阅读全文
摘要:
https://leetcode.cn/problems/rotate-list/solution/xiang-zi-xing-che-lian-yi-yang-qu-xuan-z-di8y/ /** * Definition for singly-linked list. * type ListN 阅读全文
摘要:
https://leetcode.cn/problems/lowest-common-ancestor-of-a-binary-tree/solution/236-er-cha-shu-de-zui-jin-gong-gong-zu-xian-hou-xu/ /** * Definition for 阅读全文
摘要:
func main() { //按数组层序建立二叉树,之后层序输出二叉树 root:=createTree(0,[]int{1,2,3,4,5,6}) ans:=printTree(root) fmt.Println(ans) //先序建立二叉树,之后先序输出二叉树 var tmp *TreeNod 阅读全文
摘要:
https://leetcode.cn/problems/intersection-of-two-linked-lists/solution/xiang-jiao-lian-biao-by-leetcode-solutio-a8jn/ /** * Definition for singly-link 阅读全文
摘要:
https://leetcode.cn/problems/er-cha-shu-de-jing-xiang-lcof/ /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNo 阅读全文
摘要:
https://leetcode.cn/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/ func findNumberIn2DArray(matrix [][]int, target int) bool { return find2(matrix,tar 阅读全文
摘要:
https://leetcode.cn/problems/path-sum-ii/ /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNo 阅读全文
摘要:
https://leetcode.cn/problems/SLwz0R/ /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func removeNt 阅读全文