随笔分类 -  编程之道

摘要:606. 根据二叉树创建字符串 - 力扣(Leetcode) 前序遍历 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } 阅读全文
posted @ 2023-01-02 14:01 吴丹阳-V 阅读(10) 评论(0) 推荐(0) 编辑
摘要:605. 种花问题 - 力扣(Leetcode) 下面是中间有0的情况下,可以种植的个数 1 0 2 0 3 1 4 1 5 2 6 2 7 3 8 3 9 4 两边边界问题,左边我使用 begin 往后挪了两位后认为是1,右边往右挪了两位后算作1 func canPlaceFlowers(flow 阅读全文
posted @ 2023-01-01 21:27 吴丹阳-V 阅读(29) 评论(0) 推荐(0) 编辑
摘要:599. 两个列表的最小索引总和 - 力扣(Leetcode) 刚开始的思路是搞两个map,但是性能比较差,只需要构建一个map然后遍历第二个list即可 [!添加后可以过滤一些肯定不符合条件的] if k1 > indexSum { continue } func findRestaurant(l 阅读全文
posted @ 2023-01-01 17:12 吴丹阳-V 阅读(15) 评论(0) 推荐(0) 编辑
摘要:598. 范围求和 II - 力扣(Leetcode) Go语言没有针对int的最小值、最大值以及比较算法,可以有一套,不然每次都需要写这个min函数 func maxCount(m int, n int, ops [][]int) int { if m <= 0 || n <= 0 { retur 阅读全文
posted @ 2023-01-01 16:38 吴丹阳-V 阅读(8) 评论(0) 推荐(0) 编辑
摘要:595. 大的国家 - 力扣(Leetcode) 两种方法,一个是or一个是union,union会快一点 # Write your MySQL query statement below # select name, population, area from World # where area 阅读全文
posted @ 2023-01-01 14:27 吴丹阳-V 阅读(13) 评论(0) 推荐(0) 编辑
摘要:594. 最长和谐子序列 - 力扣(Leetcode) 双指针,后面那个边界条件让我调了好几分钟 func findLHS(nums []int) int { sort.Ints(nums) left, right, maxLen := 0, 0, 0 for { if nums[right] - 阅读全文
posted @ 2023-01-01 13:46 吴丹阳-V 阅读(9) 评论(0) 推荐(0) 编辑
摘要:590. N 叉树的后序遍历 - 力扣(Leetcode) 可以参考 [[leetcode-589. N 叉树的前序遍历]] ,代码差不多 /** * Definition for a Node. * type Node struct { * Val int * Children []*Node * 阅读全文
posted @ 2023-01-01 12:44 吴丹阳-V 阅读(16) 评论(0) 推荐(0) 编辑
摘要:589. N 叉树的前序遍历 - 力扣(Leetcode) Go语言的切片操作方便性还不错 /** * Definition for a Node. * type Node struct { * Val int * Children []*Node * } */ func preorder(root 阅读全文
posted @ 2023-01-01 12:35 吴丹阳-V 阅读(12) 评论(0) 推荐(0) 编辑
摘要:586. 订单最多的客户 - 力扣(Leetcode) # Write your MySQL query statement below select customer_number from ( select customer_number, count(*) cnt from Orders gr 阅读全文
posted @ 2023-01-01 12:03 吴丹阳-V 阅读(14) 评论(0) 推荐(0) 编辑
摘要:584. 寻找用户推荐人 - 力扣(Leetcode) sql 题,还是比较简单的 # Write your MySQL query statement below select name from customer where referee_id <> 2 or referee_id is nu 阅读全文
posted @ 2023-01-01 11:40 吴丹阳-V 阅读(25) 评论(0) 推荐(0) 编辑
摘要:575. 分糖果 - 力扣(Leetcode) 信息: 糖果的种类 总个数 吃一半 分析: 种类大于一半,那么只能吃一半 种类小于一半,那么是种类量 考哈希表,有点简单,熟悉Go语法还行 func distributeCandies(candyType []int) int { if len(can 阅读全文
posted @ 2023-01-01 01:24 吴丹阳-V 阅读(16) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.cn/problems/subtree-of-another-tree/description/ 需要有两个不同的递归,如果当前节点的值和另一棵树的root.Val相同,那么需要判断两棵树是否完全相等 /** * Definition for a binary tr 阅读全文
posted @ 2022-12-31 23:04 吴丹阳-V 阅读(18) 评论(0) 推荐(0) 编辑
摘要:563. 二叉树的坡度 - 力扣(Leetcode) 坡度的计算需要4个数 左子树所有节点的和 右子树所有结点的和 左子树的坡度 右子树的坡度 左子树与右子树节点差值的绝对值为当前节点的坡度 左子树与右子树的坡度与当前节点的坡度作为第二个值返回 下面的代码使用了 go 的双返回值特性,你也可以使用一 阅读全文
posted @ 2022-12-31 21:24 吴丹阳-V 阅读(19) 评论(0) 推荐(0) 编辑
摘要:559. N 叉树的最大深度 - 力扣(Leetcode) dfs /** * Definition for a Node. * type Node struct { * Val int * Children []*Node * } */ func maxDepth(root *Node) int 阅读全文
posted @ 2022-12-31 20:27 吴丹阳-V 阅读(14) 评论(0) 推荐(0) 编辑
摘要:557. 反转字符串中的单词 III - 力扣(Leetcode) 与代码 [[leetcode-541. 反转字符串 II]] 相关联,swapStrBytes 函数,使用了上次的代码 func reverseWords(s string) string { sBytes := []byte(s) 阅读全文
posted @ 2022-12-30 13:03 吴丹阳-V 阅读(13) 评论(0) 推荐(0) 编辑
摘要:551. 学生出勤记录 I - 力扣(Leetcode) 字符串序列计数 func checkRecord(s string) bool { absentCnt := 0 cLateCnt := 0 for i := 0; i < len(s); i++ { v := s[i] if uint8(v 阅读全文
posted @ 2022-12-30 12:50 吴丹阳-V 阅读(10) 评论(0) 推荐(0) 编辑
摘要:543. 二叉树的直径 - 力扣(Leetcode) 深度优先遍历,每个节点的直径等于左子树的最大深度加上右子树的最大深度,取一个最大值即可 /** * Definition for a binary tree node. * type TreeNode struct { * Val int * L 阅读全文
posted @ 2022-12-29 23:42 吴丹阳-V 阅读(19) 评论(0) 推荐(0) 编辑
摘要:541. 反转字符串 II - 力扣(Leetcode) 比较简单,想清楚边界条件,然后做一下字符的反转即可。go 可以将不能变动的字符串转换成可以变动的 []byte 之后,修改完之后,再转成 string func reverseStr(s string, k int) string { if 阅读全文
posted @ 2022-12-26 22:51 吴丹阳-V 阅读(22) 评论(0) 推荐(0) 编辑
摘要:521. 最长特殊序列 Ⅰ - 力扣(Leetcode) 脑筋急转弯 func findLUSlength(a string, b string) int { if a != b { return max(len(a), len(b)) } return -1 } func max(a,b int) 阅读全文
posted @ 2022-12-25 14:06 吴丹阳-V 阅读(11) 评论(0) 推荐(0) 编辑
摘要:520. 检测大写字母 - 力扣(Leetcode) unicode 包里面有 IsUpper 方法可以用来判断是否是大写字母 func detectCapitalUse(word string) bool { if len(word) <= 1 { return true } firstUpper 阅读全文
posted @ 2022-12-24 22:36 吴丹阳-V 阅读(13) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示