打家劫舍leetcode 198
LeetCode-146-LRU缓存
title: LeetCode-146-LRU缓存 date: 2022-11-18 23:17:17 tags: # 146题:LRU缓存 ## 题目 请你设计并实现一个满足 LRU (最近最少使用) 缓存 约束的数据结构。 实现 `LRUCache` 类: `LRUCache(int capac ......
[刷题记录Day1]Leetcode列表专题
# No.1 ## 题目 [二分查找](https://leetcode.cn/problems/binary-search/) ## 思路 - 要素:原数组升序排列 - 清楚地定义左右边界 - 优化空间:数组有序,通过第0元素和最后元素,可以避免查找不在数组范围内的target ## 代码 ``` ......
【leetcode】【234】【回文链表】
# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
[刷题记录Day3]Leetcode链表专题
```Java # ListNode definition public class ListNode { // 结点的值 int val; // 下一个结点 ListNode next; // 节点的构造函数(无参) public ListNode() { } // 节点的构造函数(有一个参数) ......
【leetcode】【206】【反转链表】
# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
【leetcode】【83】【移除链表元素】
# c++ ## 第一个方法 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; ListNode() ......
LeetCode 142. 环形链表 II
``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class ......
[刷题记录]Leetcode列表专题
# No.1 ## 题目 [Leetcode link](https://leetcode.cn/problems/squares-of-a-sorted-array/) ## 思路 * 数组本身是非降序,即最小值和最大值在数组的两端 * 非降序数组每个元素平方后,最大值在两端,最小值在中部 * 双 ......
代码随想录|打家劫舍问题
198.打家劫舍 213.打家劫舍II 337.打家劫舍III 198.打家劫舍 class Solution: def rob(self, nums: List[int]) -> int: n = len(nums) if n == 0: return 0 dp = [0 for _ in ran ......
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 19. 删除链表的倒数第 N 个结点
链表问题,需要注意一下是倒着数还是正着数,和头结点会不会被删除即可 ```java public ListNode removeNthFromEnd(ListNode head, int n) { if (head == null) { return null; } // 头结点会被删除吗? int ......
Leetcode 20. 有效的括号
可以将反括号先存入map中,而后如果当前字符能在map中查到,说明是反括号,否则是正括号。 但是结合map的使用和将反括号作为map的key,并不容易第一时间想到。 class Solution { public: bool isValid(string s) { int n = s.size(); ......
【leetcode】【83】【删除排序链表中的重复元素】
# c++ ## 第一个方法 ### 代码 ```c++ #include #include #include #include // Definition for singly-linked list. struct ListNode { int val; ListNode* next; List ......
【leetcode】【21】【合并两个有序链表】
# c++ ## 第一个方法 ### 代码 ```c++ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nul ......
https://leetcode.cn/ 第9题 判断回文数
# 回文数 121 是; 123 不是 #定义一个函数 判断是否是回文数 def get_Hui(num): #将整数num转字符串 str_num = str(num) str_num_change = str_num[::-1] num2 = int(str_num_change) #判断整数n ......
leetcode ListNode类--Java
public class ListNode { public int val; public ListNode next; public ListNode() {} public ListNode(int val) { this.val = val; } public ListNode(int va ......
leetcode TreeNode类 --java
public class TreeNode { int val; TreeNode left; TreeNode right; public TreeNode() { } public TreeNode(int val) { this.val = val; } public TreeNode(int ......
leetcode动态规划-
什么是动态规划 动态规划的定义和特点 动态规划的基本思想和步骤 动态规划的分类和常见问题 线性动态规划 最长公共子序列 最长递增子序列 最大子数组和 区间动态规划 矩阵链乘法 括号化问题 背包动态规划 0-1背包问题 完全背包问题 多重背包问题 状态压缩动态规划 旅行商问题 汉密尔顿回路问题 动态规 ......
二叉树-前序遍历-leetcode222
给你一棵 完全二叉树 的根节点 root ,求出该树的节点个数。 完全二叉树 的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层,则该层包含 1~ 2h 个节点。 示例 1: 输入:root = ......
leetcode动态规划题目总结
ref :https://leetcode.cn/circle/article/2Xxlw3/ 这是一篇我在leetcode.com上撰写的文章Dynamic Programming Summary,就不翻回中文了,直接copy过来了。 Hello everyone, I am a Chinese ......
动态规划leetcode 清单
不同的二叉搜索树 (卡特兰数) N 天后的牢房 骑士拨号器 最大为 N 的数字组合 鸡蛋掉落 石子游戏 新21点 分汤 有效的井字游戏 统计不同回文子字符串 编辑距离 买卖股票的最佳时机含手续费 爬楼梯 奇怪的打印机 不同路径 II 不同路径 出界的路径数 二叉树的直径 最大子序和 优美的排列 零钱 ......
[LeetCode] 1493. Longest Subarray of 1's After Deleting One Element
Given a binary array nums, you should delete one element from it. Return the size of the longest non-empty subarray containing only 1's in the resulti ......
动态规划-背包问题-完全背包问题:leetcode 377. 组合总和 Ⅳ
1. 题目 读题 给你一个由 不同 整数组成的数组 nums ,和一个目标整数 target 。请你从 nums 中找出并返回总和为 target 的元素组合的个数。 题目数据保证答案符合 32 位整数范围。 示例 1: 输入:nums = [1,2,3], target = 4输出:7解释:所有可 ......
7-010-(LeetCode- 518) 零钱兑换II
1. 题目 读题 518. 零钱兑换 II给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带符号整数。 ......
LeetCode C++:HashTable篇
1、Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume tha ......
leetcode 21. 合并两个有序链表
## 直接合并即可 这道题是简单题,直接合并即可 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int ......
[LeetCode] 1071. Greatest Common Divisor of Strings
For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times). Given two string ......
[LeetCode] 1186. Maximum Subarray Sum with One Deletion
Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, y ......