回文leetcode problems two-sum

LeetCode|1032. 字符流

题目链接:1032. 字符流 设计一个算法:接收一个字符流,并检查这些字符的后缀是否是字符串数组 words 中的一个字符串。 例如,words = ["abc", "xyz"] 且字符流中逐个依次加入 4 个字符 'a'、'x'、'y' 和 'z' ,你所设计的算法应当可以检测到 "axyz" 的 ......
字符 LeetCode 1032

LeetCode|1574. 删除最短的子数组使剩余数组有序

题目链接:1574. 删除最短的子数组使剩余数组有序 给你一个整数数组 arr ,请你删除一个子数组(可以为空),使得 arr 中剩下的元素是 非递减 的。 一个子数组指的是原数组中连续的一个子序列。 请你返回满足题目要求的最短子数组的长度。 示例 1: 输入:arr = [1,2,3,10,4,2 ......
数组 LeetCode 1574

leetcode1574

双指针法,结果只能从最左边或者最右边或者最左边加上最右边中取 class Solution { public: int findLengthOfShortestSubarray(vector<int>& arr) { int n = arr.size(),res = 1,res2 = 1,res3 ......
leetcode 1574

Leetcode 22. 括号生成

题目链接在这里: 还是比较经典的括号匹配问题,这题学习了函数内套子函数的写法,但是关于全局变量还是有一点问题要问问龙哥,先挖个坑放这…… from ast import List # class Solution: # def generateParenthesis(self, n: int) -> ......
括号 Leetcode 22

Leetcode 18. 四数之和(双指针)

题目链接在这里:四数之和 这道题和前面的三数之和一模一样,只是需要枚举前两个数而已,需要注意一下前两个数的重复点的判断,并且不要忘记排序。 from ast import List class Solution: def fourSum(self, nums: List, target: int): ......
之和 指针 Leetcode 18

[LeetCode] 2316. Count Unreachable Pairs of Nodes in an Undirected Graph

You are given an integer n. There is an undirected graph with n nodes, numbered from 0 to n - 1. You are given a 2D integer array edges where edges[i] ......
Unreachable Undirected LeetCode Count Graph

LeetCode 19 删除链表的倒数第N个节点

LeetCode 19 删除链表的倒数第N个节点 题目跳转链接 class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { ListNode* dummyHead=new ListNode(0); dumm ......
节点 LeetCode 19

LeetCode 24. 两两交换链表中的节点

24. 两两交换链表中的节点 力扣题目跳转链接 具体解题思路和答案可以参考:代码随想录: 24. 两两交换链表中的节点 ####自我错误思考过程记录: &#10008 错误代码: //思路: class Solution { public: ListNode* swapPairs(ListNode* ......
节点 LeetCode 24

【LeetCode动态规划#04】不同的二叉搜索树(找规律,有点像智力题)

不同的二叉搜索树 力扣题目链接(opens new window) 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 示例: 思路 题意分析 先找一下关系 当n = 1时,如果元素就是1,以1为头节点 1 当n = 2时,分别以1和2为头节点 1 2 / \ 2 1 然后当n ......
智力 LeetCode 规律 动态 04

LeetCode 59. 螺旋矩阵 II

这道题可以采用模拟法来实现。我们可以设置上下左右四个边界,然后模拟螺旋填充元素。具体来说,我们定义 left、right、top、bottom 四个变量代表当前需要填充的最左边、最右边、最上面、最下面的位置,然后根据当前位置,依次填充矩阵。 具体可以按照以下步骤实现: 初始化矩阵 matrix,并且 ......
矩阵 螺旋 LeetCode 59 II

Leetcode 17.电话号码的字母组合 (模拟)

题目链接在这里:电话号码的字母组合 这道题主要学习的是哈希表的应用:可以用大括号来代表建立哈希表,以及子函数的实现:可以直接在主函数中定义子函数,将$string$拼成一个整个的长$string:$"".join(list), 注意前面的这个空串是必要的,它代表子串之间直接相连,没有其他的字符。 f ......
电话号码 字母 Leetcode 号码 电话

Leetcode 15 & 16 (双指针)

都是比较经典的双指针问题,我们可以从中总结一些双指针的规律 首先这两题如果en做的话就是 $O(n^{3})$ 的算法,暴力去找。但是我们可以发现这三个值是满足一定约束的,所以考虑使用方法将它降到 $O(n^2)$ 。如果双指针,一个在头,一个在尾,两个向中间夹,根据约束条件合理选择向中间夹的策略, ......
指针 Leetcode amp 15 16

LeetCode|1630. 等差子数组

题目链接:1630. 等差子数组 难度中等60收藏分享切换为英文接收动态反馈 如果一个数列由至少两个元素组成,且每两个连续元素之间的差值都相同,那么这个序列就是 等差数列 。更正式地,数列 s 是等差数列,只需要满足:对于每个有效的 i , s[i+1] - s[i] == s[1] - s[0] ......
等差 数组 LeetCode 1630

LeetCode60. 排列序列

class Solution { public: int fac[10]; void init() { fac[0]=1; fac[1]=1; for(int i=2;i<10;i++) fac[i]=fac[i-1]*i; return; } string str; bool visited[10 ......
序列 LeetCode 60

代码随想录Day10-Leetcode232. 用栈实现队列,225. 用队列实现栈

### 232.用栈实现队列 尽管是很简单的一题, 但还是参考了题解, 一开始还在想,push的时候还得把输出栈倒回来效率好低 结果一看题解发现不用 //思路: 对对队列尾部操作时(push,empty), 对输入栈正常操作; 对队列头部操作时(peek,pop),全部弹出到输出栈中操作 //参考思 ......
队列 随想录 随想 Leetcode 代码

【LeetCode动态规划#03】整数拆分(数学题)

整数拆分 力扣题目链接(opens new window) 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。 示例 1: 输入: 2 输出: 1 解释: 2 = 1 + 1, 1 × 1 = 1。 示例 2: 输入: 10 输出: 36 解释: ......
数学题 整数 LeetCode 数学 动态

assembly of tiny problems I come across when using Ubuntu

1. flameshot couldn't work properly. after running, it doesn't act to enable selecting area as expected, but pop out a frame and I need to click 'shar ......
assembly problems across Ubuntu using

代码随想录Day9-Leetcode28. 实现 strStr(),459.重复的子字符串

28. 实现 strStr() 这题之前写过, 而且印象深刻的是细节很多,所以这边是看完以前的代码,再写的(几乎是在背代码了hhh) 甚至这样, next[0]=-1, 和j开始匹配子串是没初始化成0这样的细节还是忘了 手撕kmp感觉光靠理解是有困难的 /** * @param {string} h ......

代码随想录Day8-Leetcode344.反转字符串 II,541. 反转字符串II ,剑指Offer 05.替换空格 ,151.翻转字符串里的单词,剑指Offer58-II.左旋转字符串

344. 反转字符串 题目链接:https://leetcode.cn/problems/reverse-string 明显的双指针 /** * @param {character[]} s * @return {void} Do not return anything, modify s in-p ......
字符串 字符 随想录 左旋 Offer

[LeetCode] 1032. Stream of Characters

Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings words. For ......
Characters LeetCode Stream 1032 of

LeetCode——45. 跳跃游戏 II

LeetCode链接 45. 跳跃游戏 II 给定一个长度为 n 的 0 索引整数数组 nums。初始位置为 nums[0]。 每个元素 nums[i] 表示从索引 i 向前跳转的最大长度。换句话说,如果你在 nums[i] 处,你可以跳转到任意 nums[i + j] 处: 0 <= j <= n ......
LeetCode 45 II

【LeetCode动态规划#02】图解不同路径I + II(首次涉及二维dp数组,)

不同路径 力扣题目链接(opens new window) 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。 问总共有多少条不同的路径? 示例 1: 输入 ......
数组 路径 LeetCode 动态 02

LeetCode28. 找出字符串中第一个匹配项的下标

题目描述: 给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。 如果 needle 不是 haystack 的一部分,则返回 -1 。 示例 1: 输入:haystack = "sadbutsa ......
下标 字符串 字符 LeetCode 28

leetcode-1480-easy

Running Sum of 1d Array Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nu ......
leetcode 1480 easy

leetcode-1450-easy

Number of Students Doing Homework at Given Time Given two integer arrays startTime and endTime and given an integer queryTime. The ith student started ......
leetcode 1450 easy

leetcode-1437-easy

Check If All 1's Are at Least Length K Places Away Given an binary array nums and an integer k, return true if all 1's are at least k places away from ......
leetcode 1437 easy

leetcode-1317-easy

Find the Distance Value Between Two Arrays Given two integer arrays arr1 and arr2, and the integer d, return the distance value between the two arrays ......
leetcode 1317 easy

Leetcode(剑指offer专项训练)——DP专项(2)

三角形中最小路径之和 1.题目描述 给定一个三角形 triangle ,找出自顶向下的最小路径和。 每一步只能移动到下一行中相邻的结点上。相邻的结点 在这里指的是 下标 与 上一层结点下标 相同或者等于 上一层结点下标 + 1 的两个结点。也就是说,如果正位于当前行的下标 i ,那么下一步可以移动到 ......
专项 Leetcode offer

Leetcode Practice -- 字符串

14. 最长公共前缀 编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 ""。 输入:strs = ["flower","flow","flight"] 输出:"fl" 思路解析 string longestCommonPrefix(vector<string>& s ......
字符串 字符 Leetcode Practice

Leetcode(剑指offer专项训练)——DP专项(1)

路径的数目 题目: 一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。 机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish” )。 问总共有多少条不同的路径 链接 思路: 这是一道基础的DP题目,走到位置(1,1)只 ......
专项 Leetcode offer