随笔分类 - 刷题笔记
摘要:union合并两个或多个 SELECT 语句的结果集 UNION 内部的 SELECT 语句必须拥有相同数量的列。列也必须拥有相似的数据类型。同时,每条 SELECT 语句中的列的顺序必须相同。 不去重使用union all,去重使用union select device_id, gender, a
阅读全文
摘要:https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/ class Solution { LinkedList<List<Integer>> res = new LinkedList<>
阅读全文
摘要:https://leetcode-cn.com/problems/add-digits/ 使用递归就行 class Solution { public int addDigits(int num) { if(num < 10) return num; int next = 0; while(num
阅读全文
摘要:https://leetcode-cn.com/problems/open-the-lock/ 题目类型:BFS class Solution { //将s[j]向上拨动一次 String plusOne(String s, int j){ char[] ch = s.toCharArray();
阅读全文
摘要:https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/ 使用动态规划 使用返回a,是因为,当使用b返回的时候需要考虑n == 0 的特例 class Solution { public int fib(int n) { int a =
阅读全文
摘要:https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/ 使用摩尔投票,使用两个变量。遍历数组 第一个记录当前遍历的数组的值,第二个记录当前遍历数字出现的次数 如果下一个
阅读全文
摘要:class Solution { public boolean verifySequenceOfBST(int [] sequence) { Stack<Integer> stack = new Stack<>(); int root = Integer.MAX_VALUE; for(int i =
阅读全文
摘要:https://www.nowcoder.com/practice/7d9a7b2d6b4241dbb5e5066d7549ca01?tpId=199&tags=&title=&difficulty=0&judgeStatus=0&rp=0 SELECT COUNT(gender) as male_
阅读全文
摘要:https://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8?tpId=13&tags=&title=&difficulty=0&judgeStatus=0&rp=0 解题思路: 遍历异或,把那些出现两次的消掉。剩下的就是x,y
阅读全文
摘要:https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/ class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { return (A != null &&
阅读全文
摘要:https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/ 使用二分,左右指针,再mid和他们比。 https://www.acwing.com/solution/content/727/ class Sol
阅读全文
摘要:https://programmercarl.com/%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E8%BF%AD%E4%BB%A3%E9%81%8D%E5%8E%86.html
阅读全文
摘要:https://leetcode-cn.com/problems/maximum-binary-tree/ 先遍历找到合适的根节点,在以此递归构造 class Solution { /* 主函数 */ public TreeNode constructMaximumBinaryTree(int[]
阅读全文
摘要:https://leetcode-cn.com/problems/populating-next-right-pointers-in-each-node/ 看代码,很容易理解 class Solution { public Node connect(Node root) { if (root ==
阅读全文
摘要:https://leetcode-cn.com/problems/invert-binary-tree/ 翻转整棵树就是交换每个节点的左右子节点,于是把交换左右子节点的代码放在了前序遍历的位置 把交换左右子节点的代码复制粘贴到后序遍历的位置也可以 class Solution { public Tr
阅读全文
摘要:https://leetcode-cn.com/problems/implement-queue-using-stacks/ class MyQueue { Stack<Integer> stackIn; Stack<Integer> stackOut; /** Initialize your da
阅读全文
摘要:redo log redo log 是 InnoDB 引擎特有的日志 更新过程: 当有一条记录需要更新的时候,InnoDB 引擎就会先把记录写到 redo log(粉板)里面,并更新内存,这个时候更新就算完成了。同时,InnoDB 引擎会在适当的时候,将这个操作记录更新到磁盘里面,而这个更新往往是在
阅读全文
摘要:https://leetcode-cn.com/problems/reverse-words-in-a-string/ 方法一:使用双端队列 方法二:自定义api 对于java来说,字符串不可变,所以两个方法的时间,空间复杂度都相同 class Solution { public String re
阅读全文
摘要:https://leetcode-cn.com/problems/ransom-note/ 维护一个字母长度的数组,遍历字母来源的字符串,在数组中将相对的字母位置加一 在所给的字符串中遍历看是否有对应的字母在数组中,有的话值-- class Solution { public boolean can
阅读全文