这题好难。自己没想到用动态规划,敲了很久,敲出了可以通过400个测试点的代码,还是有一些情况没有考虑到。不舍得删,记录一下。对输入用例 "aaa" "abac*a" 不能给出正确答案。 class Solution { public boolean isMatch(String s, String ...
分类:
其他好文 时间:
2021-03-16 13:45:02
阅读次数:
0
#111. 二叉树的最小深度 https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/ 关键在于知道f(root)=min(f(left),f(right))+1这个表达式 class Solution { public: int ...
分类:
其他好文 时间:
2021-03-16 12:04:09
阅读次数:
0
给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。 class Solution: def removeElements(self, head: ListNode, val: int) -> ListNode: ...
分类:
其他好文 时间:
2021-03-16 11:53:35
阅读次数:
0
88. 合并两个有序数组 LeetCode_88 题目描述 方法一:暴力法 class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { for(int i=0, j=0; j<n;){ if(i >= m ...
分类:
编程语言 时间:
2021-03-16 11:51:29
阅读次数:
0
错解 class Solution: def reverseWords(self, s: str) -> str: a=[] s=s.split() for i in s: if i!='': left=0 right=len(i)-1 while left <right: i[left],i[ri ...
分类:
其他好文 时间:
2021-03-15 11:18:18
阅读次数:
0
问题 序列化二叉树的一种方法是使用前序遍历。当我们遇到一个非空节点时,我们可以记录下这个节点的值。如果它是一个空节点,我们可以使用一个标记值记录,例如 #。 示例 输入: "9,3,4,#,#,1,#,#,2,#,6,#,#" 输出: true 解答 class Solution { public: ...
分类:
其他好文 时间:
2021-03-12 14:19:20
阅读次数:
0
问题 请完成一个函数,输入一个二叉树,该函数输出它的镜像。 示例 解答1:递归 class Solution { public: TreeNode* mirrorTree(TreeNode* root) { if (!root) return nullptr; // 前序操作 swap(root-> ...
分类:
其他好文 时间:
2021-03-11 17:54:57
阅读次数:
0
Description Link. 给定一棵 \(n\) 个点的树,设 \(E\) 为边集,\(V'_x,\ V'_y\) 分别为删去边 \((x,y)\) 后 点 \(x\) 所在的树的点集和点 \(y\) 所在的树的点集,求: \[ \sum_{(u,v)\in E}(\sum_{x\in V' ...
分类:
其他好文 时间:
2021-03-10 12:54:10
阅读次数:
0
###1.我的解题代码 class Solution { public boolean containsDuplicate(int[] nums) { boolean flag = false; HashSet<Integer> set = new HashSet<>(); for(int i:nu ...
分类:
编程语言 时间:
2021-03-09 12:58:00
阅读次数:
0
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。 你可以按任意顺序返回答案。 示例 1: 输入:nums = [2,7,11,15], tar ...
分类:
其他好文 时间:
2021-03-09 12:56:44
阅读次数:
0