leetcode-数组
118. 杨辉三角class Solution: def generate(self, numRows: int) - List[List[int]]: result [] for i in range(numRows): now [1]*(i1) if i 1: for i in range(1, i): now[i] pre[i - 1] pre[i] result [now] pre now return result1122. 数组的相对排序class Solution: def relativeSortArray(self, arr1: List[int], arr2: List[int]) - List[int]: res [] for i in arr2: while i in arr1: res.append(i) arr1.remove(i) return ressorted(arr1)566重塑矩阵class Solution: def matrixReshape(self, nums: List[List[int]], r: int, c: int) - List[List[int]]: if r * c ! len(nums) * len(nums[0]): return nums if r len(nums): return nums val [] for i in nums: val i res [] for i in range(0, len(val), c): res.append(val[i:i c]) return res766. 托普利茨矩阵class Solution: def isToeplitzMatrix(self, matrix: List[List[int]]) - bool: #如何取出对角线元素转化为判断前一行除了最后和后一行除了第一是否相同 for i in range(1, len(matrix)): if matrix[i - 1][:-1] ! matrix[i][1:]: return False return True1160. 拼写单词class Solution: def countCharacters(self, words: List[str], chars: str) - int: #如何判断一个字符串里面的元素是否在另外一个字符串当中 d {} num 0 for i in chars: if i not in d.keys(): d[i] 1 else: d[i] 1 print(d) for w in words: for t in w: if t not in d.keys() or w.count(t) d[t]: break else: print(w) num len(w) return num169. 求众数class Solution: def majorityElement(self, nums: List[int]) - int: dic {c:nums.count(c) for c in set(nums)} val max(dic.values()) for k, v in dic.items(): if v val: return k985. 查询后的偶数和class Solution: def sumEvenAfterQueries(self, A: List[int], queries: List[List[int]]) - List[int]: ret [] tmp sum([i for i in A if i % 2 0]) for querie in queries: old A[querie[1]] A[querie[1]] querie[0] new A[querie[1]] if old % 2 0 and new % 2 0: tmp querie[0] elif old % 2 0 and new % 2 1: tmp - old elif old % 2 1 and new % 2 0: tmp new else: tmp 0 ret.append(tmp) return ret283. 移动零class Solution: def moveZeroes(self, nums: List[int]) - None: for i in range(nums.count(0)): nums.remove(0) nums.append(0)27. 移除元素class Solution: def removeElement(self, nums: List[int], val: int) - int: for i in range(nums.count(val)): nums.remove(val)122. 买卖股票的最佳时机 IIclass Solution: def maxProfit(self, prices: List[int]) - int: tmp [] for i in range(1, len(prices)): tmp.append(prices[i] - prices[i - 1]) return sum([i for i in tmp if i 0])1089.复写0class Solution: def duplicateZeros(self, arr: List[int]) - None: Do not return anything, modify arr in-place instead. i 0 while i len(arr): if arr[i] 0: arr.insert(i, 0) arr.pop() i 2 else: i 1485. 最大连续1的个数class Solution: def findMaxConsecutiveOnes(self, nums: List[int]) - int: s .join([str(x) for x in nums]) return max(len(i) for i in s.split(0))448. 找到所有数组中消失的数字class Solution: def findDisappearedNumbers(self, nums: List[int]) - List[int]: a set(nums) ret [] for i in range(1, len(nums) 1): if i not in a: ret.append(i) return ret268. 缺失数字class Solution: def missingNumber(self, nums: List[int]) - int: # ret sum([i for i in range(len(nums) 1)]) n len(nums) ret (n * (n 1))//2 return (ret - sum(nums))217. 存在重复元素class Solution: def containsDuplicate(self, nums: List[int]) - bool: return len(set(nums)) ! len(nums)167. 两数之和 II - 输入有序数组class Solution: def twoSum(self, numbers: List[int], target: int) - List[int]: d {} for i, n in enumerate(numbers): if target - n in d.keys(): return [d[target - n] 1, i 1] d[n] i896. 单调数列class Solution: def isMonotonic(self, A: List[int]) - bool: a [] for i in range(1, len(A)): a.append(A[i] -A[i - 1]) b [0 if i 0 else -1 for i in a] c [-1 if i 0 else 0 for i in a] print(b,c) if b.count(0) len(A) - 1 or c.count(-1) len(A) - 1: return True return False977. 有序数组的平方class Solution: def sortedSquares(self, A: List[int]) - List[int]: return sorted(i * i for i in A)1051. 高度检查器class Solution: def heightChecker(self, heights: List[int]) - int: b sorted(heights) cnt 0 for i in zip(b,heights): if i[0] - i[1] ! 0: cnt 1 return cnt832. 翻转图像class Solution: def flipAndInvertImage(self, A: List[List[int]]) - List[List[int]]: return [[1-i for i in l][::-1] for l in A]

相关新闻

Leetcode 99. 恢复搜索二叉树

Leetcode 99. 恢复搜索二叉树

Time: 20190901 题目描述 二叉搜索树中的两个节点被错误地交换。 请在不改变其结构的情况下,恢复这棵树。 示例 1: 输入: [1,3,null,null,2]1/3\2输出: [3,1,null,null,2]3/1\2示例 2: 输入: [3,1,4,null,null,2]3/ \ 1 4/2输出: [2,1,4,null,null,3]2/ \ 1 4/3…

2026/7/28 18:15:08 阅读更多 →
简单总结面向对象

简单总结面向对象

面向对象 (Object Oriented,OO) 面对对象的思想对软件开发相当重要,它的概念和应用甚至已超越了程序设计和软件开发,扩 展到如数据库系统、交互式界面、应用结构、应用平台、分布式系统、网络管理结构、CAD 技术、人工智能等领域。面向对象是一种 对现实…

2026/7/28 18:15:08 阅读更多 →
[数据结构]一般顺序表部分总结

[数据结构]一般顺序表部分总结

部分顺序表算法的总结。Min/Max 顺序表使用下标i记录位置&#xff0c;链表使用指针Min/Max来指向对应结点。 int Min0; for(int i1;i<n;i){if(data[i]<data[Min])Mini; } //顺序表Node *MinL; Node *pL; while(p){if(p->data<Min->data)Minp;pp->next; } …

2026/7/28 18:15:08 阅读更多 →

最新新闻

如何用AI图层分离技术5分钟完成专业设计工作

如何用AI图层分离技术5分钟完成专业设计工作

如何用AI图层分离技术5分钟完成专业设计工作 【免费下载链接】layerdivider A tool to divide a single illustration into a layered structure. 项目地址: https://gitcode.com/gh_mirrors/la/layerdivider 在数字设计领域&#xff0c;图层分离一直是一项耗时且技术性…

2026/7/28 18:23:11 阅读更多 →
国家中小学智慧教育平台电子课本下载完整指南:三步获取所有教材PDF

国家中小学智慧教育平台电子课本下载完整指南:三步获取所有教材PDF

国家中小学智慧教育平台电子课本下载完整指南&#xff1a;三步获取所有教材PDF 【免费下载链接】tchMaterial-parser 国家中小学智慧教育平台 电子课本下载工具&#xff0c;帮助您从智慧教育平台中获取电子课本的 PDF 文件网址并进行下载&#xff0c;让您更方便地获取课本内容。…

2026/7/28 18:23:11 阅读更多 →
300. 最长上升子序列

300. 最长上升子序列

思路一&#xff1a;动态规划 建立dp表&#xff0c;dp[i]表示含第i个数字的最长上升子序列的长度 求dp[i]时&#xff0c;向前遍历找出比i元素小的元素j&#xff0c;则动态方程为dp[i] max(dp[i],dp[j] 1) class Solution(object):def lengthOfLIS(self, nums):size len(nums)…

2026/7/28 18:23:11 阅读更多 →
5分钟找回QQ空间全部历史说说的终极指南:GetQzonehistory使用教程

5分钟找回QQ空间全部历史说说的终极指南:GetQzonehistory使用教程

5分钟找回QQ空间全部历史说说的终极指南&#xff1a;GetQzonehistory使用教程 【免费下载链接】GetQzonehistory 获取QQ空间发布的历史说说 项目地址: https://gitcode.com/GitHub_Trending/ge/GetQzonehistory 你是否曾想找回那些被时间淹没的QQ空间历史说说&#xff1…

2026/7/28 18:23:11 阅读更多 →
JSP总结

JSP总结

JSP总结 文章目录JSP总结一.jsp工作原理和生命周期二.jsp内置对象三.incude指令和include行为四.jsp作用域五.cookie和session一.jsp工作原理和生命周期 工作原理&#xff1a; 执行过程以hello.jsp为例&#xff1a; 把 hello.jsp转译为hello_jsp.javahello_jsp.java 位于 d:…

2026/7/28 18:23:10 阅读更多 →
EDA 工程师竞业锁定、空窗 2 年:合规赚钱完整方案(零违约风险,杜绝赔付违约金)

EDA 工程师竞业锁定、空窗 2 年:合规赚钱完整方案(零违约风险,杜绝赔付违约金)

EDA 工程师竞业锁定、空窗 2 年&#xff1a;合规赚钱完整方案&#xff08;零违约风险&#xff0c;杜绝赔付违约金&#xff09;先确立核心法理底线&#xff1a; 竞业限制禁止三类行为&#xff08;无论全职 / 兼职 / 外包 / 顾问 / 项目合作&#xff09;入职存在实质竞争关系的 E…

2026/7/28 18:22:10 阅读更多 →

日新闻

告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿!3步让你的暗影精灵笔记本重获新生

告别臃肿&#xff01;3步让你的暗影精灵笔记本重获新生 【免费下载链接】OmenSuperHub Control Omen laptop performance, fan speeds, and keyboard lighting, and unlock power limits. 项目地址: https://gitcode.com/gh_mirrors/om/OmenSuperHub 你是否也曾为官方Om…

2026/7/28 0:00:43 阅读更多 →
RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

RAG必踩坑!财报法规检索不准?这款开源工具让答案浮出水面,准确率飙升98.7%!

做 RAG 的人应该都踩过这个致命的坑&#xff1a;把几百页的财报、法规、技术手册扔给向量库&#xff0c;问一个具体问题&#xff0c;搜出来的全是沾边但没用的内容 —— 关键信息要么被硬切块拆碎了&#xff0c;要么藏在几十条结果的最下面。语义相似≠真正相关&#xff0c;这个…

2026/7/28 0:00:43 阅读更多 →
抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

抖音视频文案提取工具全指南:免费2026版、手机App、在线工具一网打尽

2026年做短视频运营&#xff0c;从抖音上扒文案早就不是偷偷抄笔记的事了。我刚开始做内容的时候&#xff0c;每天刷半小时抖音&#xff0c;手动把爆款视频的口播敲进备忘录&#xff0c;一条2分钟的视频得花十来分钟&#xff0c;碰到语速快的还要反复回听。后来试了一圈工具&am…

2026/7/28 0:00:43 阅读更多 →

周新闻

深度学习道路桥梁裂缝检测系统 道路桥梁裂缝检测数据集 道路桥梁病害识别检测数据集

深度学习道路桥梁裂缝检测系统 道路桥梁裂缝检测数据集 道路桥梁病害识别检测数据集

深度学习道路桥梁裂缝检测系统 数据集6000张 完整源码已标注数据集训练好的模型环境配置教程程序运行说明文档&#xff0c;可以直接使用&#xff01;系统支持图片、视频、摄像头等多种方式检测裂缝&#xff0c;功能强大实用。 1数据集6000张 8各类别

2026/7/28 12:04:22 阅读更多 →
深度学习YOLO模型如何训练 PUBG 绝地求生目标检测数据集

深度学习YOLO模型如何训练 PUBG 绝地求生目标检测数据集

pubg数据集 精选原图1.42万数据 1.49万标签 无任何重复、算法增强或冗余图像&#xff01; pubg绝地求生目标检测数据集 1分类&#xff1a;e_body&#xff0c;14905个标签&#xff0c;txt格式 共计14244张图&#xff0c;99%为640*640尺寸图像 适合yolo目标检测、AI训练关键词&am…

2026/7/28 8:29:16 阅读更多 →
Apex英雄目标检测数据集 深度学习框架YOLO如何训练APEX数据集

Apex英雄目标检测数据集 深度学习框架YOLO如何训练APEX数据集

Apex检测数据集数据集详情检测类别&#xff1a; allies enemy tag图片总量&#xff1a;7247张训练集&#xff1a;5139张验证集&#xff1a;1425张测试集&#xff1a;683张标注状态&#xff1a;全部已标注&#xff0c;即拿即用数据格式&#xff1a;支持YOLO格式及其他格式&#…

2026/7/28 5:03:42 阅读更多 →

月新闻