随笔分类 - LeetCode
669. Trim a Binary Search Tree 修剪二叉搜索树 Java
摘要:题目要求对一棵二叉搜索树进行规定的修剪:剪去小于x的,大于y的。 我们只需要递归地对树的左子树右子树进行修剪即可。 所有情况如下: 根root的值不在(x,y)内,则判断是小于x还是大于y,分别返回右子树的修剪和左子树的修剪(因为如果root小于x,那么它的左子树必定都小于x,所以我们只需考虑它的右
阅读全文
213. House Robber II 打家劫舍 IIJava
摘要:网址:https://leetcode.com/problems/house-robber-ii/ 因为房子是环形排列的,所以第一个房子和最后一个房子是相邻关系。 于是我们就在House Robber的基础上稍加修改即可: 打劫范围为第一间房子到倒数第二间房子 打劫范围为第二件房子到最后一间房子 选
阅读全文
198. House Robber 强盗抢劫 Java
摘要:网址:https://leetcode.com/problems/house-robber/ 参考:https://leetcode.com/problems/house-robber/discuss/156523/From-good-to-great.-How-to-approach-most-o
阅读全文
94. Binary Tree Inorder Traversal二叉树的中序遍历
摘要:网址:https://leetcode.com/problems/binary-tree-inorder-traversal/ 参考:https://leetcode.com/problems/binary-tree-inorder-traversal/solution/ 二叉树的遍历一般有两种办法
阅读全文
654. Maximum Binary Tree最大二叉树
摘要:网址:https://leetcode.com/problems/maximum-binary-tree/ 参考: https://leetcode.com/problems/maximum-binary-tree/discuss/106146/C%2B%2B-O(N)-solution 我自己的做
阅读全文
102. Binary Tree Level Order Traversal二叉树层序遍历
摘要:网址:https://leetcode.com/problems/binary-tree-level-order-traversal/ 参考:https://www.cnblogs.com/grandyang/p/4051321.html 二叉树的层次遍历的做法是维护一个队列,不断使节点入队,使用了
阅读全文
983. Minimum Cost For Tickets
摘要:网址:https://leetcode.com/problems/minimum-cost-for-tickets/ 参考:https://leetcode.com/problems/minimum-cost-for-tickets/discuss/226659/Two-DP-solutions-w
阅读全文
229. Majority Element II求众数II
摘要:网址:https://leetcode.com/problems/majority-element-ii/ 参考:https://blog.csdn.net/u014248127/article/details/79230221 摩尔投票算法( Boyer-Moore Voting Algorith
阅读全文
169. Majority Element求众数
摘要:网址:https://leetcode.com/problems/majority-element/ 参考:https://blog.csdn.net/u014248127/article/details/79230221 不断的消去两个不同的数,最后剩下的数肯定是所求的众数! 细节:
阅读全文
567. Permutation in String字符串的排列(效率待提高)
摘要:网址:https://leetcode.com/problems/permutation-in-string/ 参考:https://leetcode.com/problems/permutation-in-string/discuss/102588/Java-Solution-Sliding-Wi
阅读全文
51. N-Queens N皇后
摘要:网址:https://leetcode.com/problems/n-queens/ 类似见:https://www.cnblogs.com/tornado549/p/10701124.html
阅读全文
52. N-Queens II N皇后II
摘要:网址:https://leetcode.com/problems/n-queens-ii/ 方法1:按照逻辑思路,通过回溯法解决问题。速度较慢! 方法2:位运算 参考:https://www.bilibili.com/video/av46292575/?p=43
阅读全文
322. Coin Change零钱兑换
摘要:网址:https://leetcode.com/problems/coin-change/ 典型的动态规划问题,类比背包问题,这就是完全背包问题
阅读全文
43. Multiply Strings字符串相乘
摘要:网址:https://leetcode.com/problems/multiply-strings/submissions/ 参考:https://leetcode.com/problems/multiply-strings/discuss/17605/Easiest-JAVA-Solution-w
阅读全文
977. Squares of a Sorted Array有序数组的平方
摘要:网址:https://leetcode.com/problems/squares-of-a-sorted-array/ 双指针法 把左端的元素和右端的元素比较后挑出绝对值大的,将其平方放入ans中,并且将指针往中间移动 不断循环上述过程,直至两指针重合。注意处理重合位置 最后将 ans 通过 rev
阅读全文
1018. Binary Prefix Divisible By 5可被 5 整除的二进制前缀
摘要:网址:https://leetcode.com/problems/binary-prefix-divisible-by-5/ 一次for循环遍历数组,在上次计算的基础上得到本次的结果!
阅读全文
1021. Remove Outermost Parentheses删除最外层的括号
摘要:网址:https://leetcode.com/problems/remove-outermost-parentheses/ 使用栈的思想,选择合适的判断时机 删除最外层的括号
阅读全文
1022. Sum of Root To Leaf Binary Numbers从根到叶的二进制数之和
摘要:网址:https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/ 递归调用求和,同时注意%1000000007的位置
阅读全文
3. Longest Substring Without Repeating Characters无重复字符的最长子串
摘要:网址:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 显然采用sliding window滑动窗口法,辅助以哈希表,判断字符是否已使用 不断扩充 j,直到 s[j] 已经使用 此时,把 i 移
阅读全文
浙公网安备 33010602011771号