随笔分类 - 刷题笔记
摘要:因为是有序的,所以用双指针就行 https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/ class Solution { public int[] twoSum(int[] nums, int target) { int i
阅读全文
摘要:https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/ 使用双指针 **部分API解释:** **StringBuilder**:Java编译器对String做了特殊处理,使得我们可以直接用+拼接字符串。虽然可以直接 拼接字符串
阅读全文
摘要:https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/ 大体的思路都是一样的,但是代码有两种写法,值得自己去学习 DFS class Solution { public int maxDepth(TreeNode root) { if
阅读全文
摘要:https://leetcode-cn.com/problems/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof/ 这道题我还是不知道为什么会超时 做题的时候不要去回想题解的代码a,要去自己理解,自己敲自己的代码 错误示范: 超时 pub
阅读全文
摘要:https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/ 代码能够自己理解了,但是题解中的一些问题还是没有解决 class Solution { public int maxSubArray(int[] nums) {
阅读全文
摘要:https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/ class Solution { public boolean isSymmetric(TreeNode root) { return root == null ? true
阅读全文
摘要:https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements/ 如果只是让所有的元素相等,那么让一个数加多少和让一个数减多少是没有区别的 思路很简单,让所有的数减到与最小的数相等,计算数组中所有元素与最小数字差值的总和
阅读全文
摘要:2 = 1.next 1.next = 0 0 = 1 1 = 2 ListNode prev = null; ListNode curr = head; while(curr != null){ ListNode next = curr.next; curr.next = prev; prev =
阅读全文
摘要:https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/ 思路 创建一个辅助栈,将第一个序列按照压入顺序压入辅助栈,此时判断辅助栈栈顶元素与第二序列的第i个元素是否相等,如果不相等,第一序列继续压,如果辅助栈的栈顶与第二序
阅读全文
摘要:https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/ 双指针: 前后指针,就像快排的模板,判断奇偶,交换 正解代码 class Solution { pu
阅读全文
摘要:https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/ 借助第三条链表[伪头节点] 在新初始化的链表中没有节点可以使用,一开始添加节点的时候有些无从下手,所以我们要初始化一个辅助节点,将节点添加到他的后面
阅读全文
摘要:在交换两个数字的时候,一定要注意分为值传递和地址传递 参考博文: https://blog.csdn.net/qq_21989927/article/details/107445722
阅读全文
摘要:剑指-22 https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/ 使用最简单的思路,遍历整个链表 使用双指针,可以不用遍历整个链表 1.先将两个指针指向头结点 2.fast 向前移动k步,然后fa
阅读全文
摘要:struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; struct ListNode 有它的内部数据“val”,它是一个int,因为它是一个列表节点,它包含一个指向下一个ListNo
阅读全文
摘要:在负奇数的时候得出的计算结果是不一样的 原因在于: 右移一位的时候,数字的二进制右移n位相当于乘以2的n次方,左一一位相当与乘以2 -7 二进制: 1111111111111111111111111111111111111111111111111111111111111001 右移一位
阅读全文
摘要:在刷题的过程中,遇到的问题,那题目来举例子: 力扣第一题: 两数之和 https://leetcode-cn.com/problems/two-sum/ class Solution { public: vector<int> twoSum(vector<int>& nums, int target
阅读全文
摘要:语法 for(int num: nums) 首先,nums是一个数组,里面放的是int类型的数据,然后定义了一个int类型的变量num,每循环一次,就从nums数组中取出一个数据来打印。 int :表示你要遍历的集合的类型 nums:表示你要遍历的集合的名 num:表示你每遍历集合中一个元素 便存储
阅读全文