leetcode 110

【leetcode】【剑指 Offer 06】【从尾到头打印链表】

# c++ ## 第一个方法 ```c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) ......
leetcode Offer

【LeetCode】矩阵中的和

``` 给你一个下标从 0 开始的二维整数数组 nums 。一开始你的分数为 0 。你需要执行以下操作直到矩阵变为空: 矩阵中每一行选取最大的一个数,并删除它。如果一行中有多个最大的数,选择任意一个并删除。 在步骤 1 删除的所有数字中找到最大的一个数字,将它添加到你的 分数 中。 请你返回最后的 ......
矩阵 LeetCode

【笔试实战】LeetCode题单刷题-编程基础 0 到 1【二】

博客推行版本更新,成果积累制度,已经写过的博客还会再次更新,不断地琢磨,高质量高数量都是要追求的,工匠精神是学习必不可少的精神。因此,大家有何建议欢迎在评论区踊跃发言,你们的支持是我最大的动力,你们敢投,我就敢肝 ......
笔试 实战 LeetCode 基础

LeetCode 148. 排序链表

``` class Solution { public: ListNode* sortList(ListNode* head) { if(!head||!head->next) return head; ListNode* fast=head,*slow=head; while(fast->next ......
LeetCode 148

LeetCode 501. 二叉搜索树中的众数

#题目链接: [LeetCode 501. 二叉搜索树中的众数](https://leetcode.cn/problems/find-mode-in-binary-search-tree/description/) ##题意: **给你一个含重复值的二叉搜索树(BST)的根节点 root ,找出并返 ......
LeetCode 501

LeetCode 图

200. 岛屿数量 695. 岛屿的最大面积 精品题解 https://leetcode.cn/problems/number-of-islands/solution/dao-yu-lei-wen-ti-de-tong-yong-jie-fa-dfs-bian-li-/ 注意深度优先遍历,对一格陆地 ......
LeetCode

[Leetcode Weekly Contest]350

链接:[LeetCode](https://leetcode-cn.com/contest/weekly-contest-350/) ## [Leetcode]2739. 总行驶距离 卡车有两个油箱。给你两个整数,mainTank 表示主油箱中的燃料(以升为单位),additionalTank 表示 ......
Leetcode Contest Weekly 350

LeetCode 146. LRU缓存机制

``` class LRUCache { public: struct node { int key,val; node *l,*r; node(int a,int b) { l=r=NULL; key=a; val=b; } }*L,*R; unordered_map mp;//保存key和节点的 ......
缓存 LeetCode 机制 146 LRU

每日一题 力扣 445 https://leetcode.cn/problems/add-two-numbers-ii/

可以直接用栈去做就行,逆序想到栈的做法 然后算完一个就直接赋值给答案数组 我用的是常见 public ListNode addTwoNumbers(ListNode l1, ListNode l2) { int sizeA=0; int sizeB=0; ListNode start=l1; Lis ......

leetcode933使用队列

输入的时间是递增的 输出 的时[t-3000,t] queue <int>q; int ping(int t){ q.push(t); while(q.front<t-3000){ q,pop(); } return q.size(); } ......
队列 leetcode 933

LeetCode -- 767. 重构字符串

设字符串s长度为len s可以重构为相邻字符串不同时 有字符串中出现次数最多的字符 < (len + 1) >> 1 当满足上述条件时候,我们就能对其进行重构 重构法:先放置偶数位置,再放置奇数位置 c ++ class Solution { public: string reorganizeStr ......
字符串 字符 LeetCode 767

【LeetCode剑指offer#05】回文链表的两种解法+删除链表中间节点(链表的基本操作)

### 回文链表 给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false 。 示例 1: 输入:head = [1,2,2,1] 输出:true 示例 2: 输入:head = [1,2] 输出:false 提示: 链表中节点数目在范围[1 ......
回文 解法 基本操作 节点 LeetCode

【leetcode】【1474】【删除链表 M 个节点之后的 N 个节点】

# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
节点 leetcode 1474

【笔试实战】LeetCode题单刷题-编程基础 0 到 1【一】

摘要: 博客推行版本更新,成果积累制度,已经写过的博客还会再次更新,不断地琢磨,高质量高数量都是要追求的,工匠精神是学习必不可少的精神。因此,大家有何建议欢迎在评论区踊跃发言,你们的支持是我最大的动力,你们敢投,我就敢肝 ......
笔试 实战 LeetCode 基础

【leetcode】【876】【链表的中间结点】

# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
结点 leetcode 876

AcWing,第110场周赛 智商药

## [AcWing,第110场周赛 智商药](https://www.acwing.com/problem/content/5049/) tag:树状数组, 线段树,二维数点(因为有 $r$ 这个限制,算吧) 分析:当吃药时 $r$ 时,只有 $[l, r - 1]$ 的方法对答案有贡献,不难看出 ......
智商 AcWing 110

LeetCode/和等于目标值的质数对

给你一个整数n,如果两个整数 x 和 y 满足下述条件,则认为二者形成一个质数对: * 1 prime(10e6,true); bool flag = false; void getprime(){//埃氏筛预处理 for(int i=2;i> findPrimePairs(int n) { if( ......
目标值 质数 LeetCode 目标

LeetCode-Python-#27 移除元素

题目描述 给定一个数列nums和数值val,消除数列nums中与数值 val相同的元素,最终返回新数列的长度;要求:不能开辟空间分配新的数列,必须改变原输入nums数列;并对修改后的nums数列的元素顺序没有要求,可以被修改。 Examples nums=[3,2,2,3; val=3 则返回长度为 ......
LeetCode-Python LeetCode 元素 Python 27

2023/07/02 leetcode刷题记录

#### 1 无重复字符的最长子串 给定一个**字符串 s** ,请你找出其中不含有重复字符的 **最长子串** 的长度。 代码 ``` class Solution { public: int lengthOfLongestSubstring(string s) { //解题思路: //先向右遍历 ......
leetcode 2023 07 02

LeetCode-146-LRU缓存

title: LeetCode-146-LRU缓存 date: 2022-11-18 23:17:17 tags: # 146题:LRU缓存 ## 题目 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 `LRUCache` 类: `LRUCache(int capac ......
缓存 LeetCode 146 LRU

[刷题记录Day1]Leetcode列表专题

# No.1 ## 题目 [二分查找](https://leetcode.cn/problems/binary-search/) ## 思路 - 要素:原数组升序排列 - 清楚地定义左右边界 - 优化空间:数组有序,通过第0元素和最后元素,可以避免查找不在数组范围内的target ## 代码 ``` ......
Leetcode 专题 Day1 Day

【leetcode】【234】【回文链表】

# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
回文 leetcode 234

[刷题记录Day3]Leetcode链表专题

```Java # ListNode definition public class ListNode { // 结点的值 int val; // 下一个结点 ListNode next; // 节点的构造函数(无参) public ListNode() { } // 节点的构造函数(有一个参数) ......
Leetcode 专题 Day3 Day

【leetcode】【206】【反转链表】

# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
leetcode 206

【leetcode】【83】【移除链表元素】

# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
leetcode 元素

LeetCode 142. 环形链表 II

``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class ......
环形 LeetCode 142 II

[刷题记录]Leetcode列表专题

# No.1 ## 题目 [Leetcode link](https://leetcode.cn/problems/squares-of-a-sorted-array/) ## 思路 * 数组本身是非降序,即最小值和最大值在数组的两端 * 非降序数组每个元素平方后,最大值在两端,最小值在中部 * 双 ......
Leetcode 专题

LeetCode 141. 环形链表

#取巧 ``` class Solution { public: const int INF=1e9; bool hasCycle(ListNode *head) { bool res=false; auto p=head; while(p) { if(p->val==INF) { res=true ......
环形 LeetCode 141

leetcode 19. 删除链表的倒数第 N 个结点

链表问题,需要注意一下是倒着数还是正着数,和头结点会不会被删除即可 ```java public ListNode removeNthFromEnd(ListNode head, int n) { if (head == null) { return null; } // 头结点会被删除吗? int ......
结点 leetcode 19

Leetcode 20. 有效的括号

可以将反括号先存入map中,而后如果当前字符能在map中查到,说明是反括号,否则是正括号。 但是结合map的使用和将反括号作为map的key,并不容易第一时间想到。 class Solution { public: bool isValid(string s) { int n = s.size(); ......
括号 Leetcode 20