12 2022 档案

摘要: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 阅读(12) 评论(0) 推荐(0) 编辑

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