leetcode

module
v0.0.0-...-632ac27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2023 License: GPL-3.0

README

LeetCode in Go

LeetCode Algorithm/Solution in Golang

  1. One folder One problem. Each folder contains a txt file which describe the problem.
  • The solution easy to figure out (for me) is in naive*.go, the name may contain some info about method used. For the rest *.go (eg. solution.go) is the solution i learned after research (especially thank to all who contributed to the “Discuss” section for those brillant ideas !).
  • For each problem, the final solution should reach the best possible time & space complexity, before move on to the next problem.
  • Commented in Chinese (we can explain the same idea with less words).
  1. About Go, normally I only import fmt to print out the result to check quickly if the algorithm works as expected. For some problems which engage data types, i use my homemade thread-safe go data type (DEPRECATED) homemade generic thread-safe go data type. Other useful tools built during this adventure and will surely come into handy later.

  2. I didn’t specifically note down the difficulty of the problems, because it’s quite subjective and depends on your experience on some type of problem: you can easily solve some “hard” problems if you’ve figured out some sort of “template” of this type in 10 minutes, but cat get stuck for hours by some “easy” problems you are not quite familiar or you've never seen before (like 初見殺し boss in game :) ?)

# Title Tags 描述
0001 Two Sum Array HashTable 找出和为目标值的两个元素
0002 Add Two Numbers LinkedList Math Recursion 数组形式表示的两数求和
0003 Longest Substring Without Repeating Characters HashTable SlidingWindow String TwoPointers 求不含重复字母的子串的长度
0004 Median of Two Sorted Arrays Array BinarySearch DivideAndConquer 求两个有序数列的中位数
0005 Longest Palindromic Substring String DynamicProgramming 求最长回文子串
0007 Reverse Integer Math 整数反向
0008 String to Integer (atoi) Math String 字符串转整数实现
0009 Palindrome Number Math 判断整数是否为回文
0010 Regular Expression Matching Backtracking DynamicProgramming String 正则表达匹配实现
0011 Container With Most Water Array TwoPointers 确定容器的两个边界使其含水量最大化
0012 Integer to Roman Math String 整型转罗马数字
0013 Roman to Integer Math String 罗马数字转整型
0014 Longest Common Prefix String 最长公共前缀
0015 Three Sum Array TwoPointers 求所有和为0的三元组
0016 3Sum Closest Array TwoPointers 求和最接近目标值的三元组
0017 Letter Combinations of a Phone Number Backtracking HashTable String 根据电话号码找到对应的字母组合
0018 Four Sum Array HashTable TwoPointers 找出所有和为目标值的四元组
0019 Remove Nth Node From End of List LinkedList TwoPointers 从列表中移除倒数第N个元素
0020 Valid Parentheses Stack String 检查括号是否正确闭合
0021 Merge Two Sorted Lists LinkedList Recursion 融合两个排好序的链表
0022 Generate Parentheses Backtracking DynamicProgramming String 生成括号对
0023 Merge k Sorted Lists DivideAndConquer Heap LinkedList MergeSort 融合k个排好序的列表
0024 Swap Nodes in Pairs LinkedList Recursion 链表相邻两个结点对调
0025 Reverse Nodes in k-Group LinkedList Recursion 链表中k个元素一组反转组内元素
0026 Remove Duplicates from Sorted Array Array TwoPointers 移除数组中多余的元素(in place)
0027 Remove Element Array TwoPointers 移除数组中指定元素(in place)
0028 Implement strStr() String TwoPointers 找出pattern在字符串中第一次出现的位置
0030 Substring with Concatenation of All Words HashTable String TwoPointers 找出内容为"以任意顺序拼接的所有给定单词"的子串
0031 Next Permutation Array TwoPointers 按字典顺序寻找当前数组的后一个排列
0032 Longest Valid Parentheses DynamicProgramming Stack String 最长的合法括号子串
0033 Search in Rotated Sorted Array Array BinarySearch 在一个循环升序数列中寻找某数
0034 Find First and Last Position of Element in Sorted Array Array BinarySearch 在有序数列中找到某元素的起始和中止index
0035 Search Insert Position Array BinarySearch 为某数在一个升序数列中寻找插入位置
0037 Sudoku Solver Array Backtracking Matrix 数独
0039 Combination Sum Array Backtracking 找出所有和为目标值的元素(元素可重复使用)组成的列表
0040 Combination Sum II Array Backtracking 找出所有和为目标值的元素(元素不可重复使用)组成的列表
0041 First Missing Positive Array HashTable 找到数列缺失的最小正整数
0042 Trapping Rain Water Array Stack TwoPointers DynamicProgramming 计算二维地形的积水量
0043 Multiply Strings Math String 计算以字符串描述的两数的乘积
0045 Jump Game II Array Greedy 最小跳数到达终点
0046 Permutations Array Backtracking 求数列中所有元素排列组合的集合
0047 Permutations II Array Backtracking 求含重复元素数列中所有元素排列组合的集合
0048 Rotate Image Array Math Matrix 顺时针旋转矩阵
0049 Group Anagrams HashTable String 将相关联的易位词组合起来
0050 Pow(x, n) Math Recursion 实现次方运算
0051 N-Queens Array Backtracking 计算N*N的棋盘上部署N皇后的所有可能性
0052 N-Queens II Backtracking 计算N*N的棋盘上部署N皇后的所有可能性的数量
0053 Maximum Subarray Array DivideAndConquer DynamicProgramming 找到和最大的子数列
0054 Spiral Matrix Array Matrix Simulation 按顺时针螺旋输出矩阵所有元素
0055 Jump Game Array Greedy 求是否可以跳到终点
0056 Merge Intervals Array Sorting 合并重叠的区间
0057 Insert Interval Array 插入区间(如有重叠需融合)
0058 Length of Last Word String 最后一个词的长度
0059 Spiral Matrix II Array Matrix Simulation 按顺时针螺旋向矩阵中插入元素
0060 Permutation Sequence Math Recursion 在数列的所有排列组合中按字典顺序找出第k个组合
0061 Rotate List LinkedList TwoPointers 将链表的末尾移到链首
0062 Unique Paths Combinatorics DynamicProgramming Math 计算从矩阵左上角到右下角的路线数
0063 Unique Paths II Array DynamicProgramming Matrix 计算从含障碍物的矩阵左上角到右下角的路线数
0064 Minimum Path Sum Array DynamicProgramming Matrix 计算从矩阵左上角到右下角的格子值之和最小的路线
0065 Valid Number Math String 检查字符串是否为合法的数
0066 Plus One Array 以数组描述的数加一
0067 Add Binary Math String 字符串形式的二进制数相加
0069 Sqrt(x) Math BinarySearch 求平方根
0070 Climbing Stairs DynamicProgramming Math Memoization 求共有几种方法到达n
0071 Simplify Path Stack String 简化文件路径
0072 Edit Distance String DynamicProgramming 求两个字符串的距离(需要增删改操作的次数)
0073 Set Matrix Zeroes Array HashTable Matrix 将矩阵中值为0的格子的行和列都置0
0074 Search a 2D Matrix Array BinarySearch Matrix 在排好序的矩阵中找元素
0075 Sort Colors Array Sorting TwoPointers 三种颜色分类排序
0076 Minimum Window Substring HashTable SlidingWindow String TwoPointers 在A字符串中找到包含所有B字符串字母的最小子串
0077 Combinations Array Backtracking 在1到n的范围内找出所有长度为k的组合
0078 Subsets Array Backtracking BitManipulation 找出数列的所有可能子集
0079 Word Search Array Backtracking Matrix 矩阵中寻找一个单词
0080 Remove Duplicates from Sorted Array II Array TwoPointers 移除数组中多余的元素(in place)
0083 Remove Duplicates from Sorted List LinkedList 有序链表中删除重复结点
0084 Largest Rectangle in Histogram Array MonotonicStack Stack 直方图找到最到矩形
0088 Merge Sorted Array Array Sorting TwoPointers 将两个排好序的字符串in-place融合
0090 Subsets II Array Backtracking BitManipulation 找出含重复元素数列的所有可能的不重复子集
0092 Reverse Linked List II LinkedList 反转部分链表
0093 Restore IP Addresses Backtracking String 从字符串还原IP地址
0094 Binary Tree Inorder Traversal BinaryTree DepthFirstSearch Stack Tree 中序遍历输出
0095 Unique Binary Search Trees II Backtracking BinarySearchTree BinaryTree DynamicProgramming Tree 返回从n个结点能构造的所有BST
0096 Unique Binary Search Trees BinarySearchTree BinaryTree DynamicProgramming Math Tree 计算n个结点可以构造多少个BST
0098 Validate Binary Search Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 判断树是否为BST
0099 Recover Binary Search Tree BinaryTree BinarySearchTree DepthFirstSearch Tree swap一对错位的结点使树成为BST
0100 Same Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 判断两棵树是否相同
0101 Symmetric Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 判断树是否对称
0105 Construct Binary Tree from Preorder and Inorder Traversal Array BinaryTree DivideAndConquer HashTable Tree 从前序遍历和中序遍历列表构建树
0106 Construct Binary Tree from Inorder and Postorder Traversal Array BinaryTree DivideAndConquer HashTable Tree 从中序遍历和后序遍历列表构建树
0108 Convert Sorted Array to Binary Search Tree Array BinaryTree BinarySearchTree DivideAndConquer Tree 从升序数列构建BST
0109 Convert Sorted List to Binary Search Tree BinaryTree BinarySearchTree DivideAndConquer LinkedList Tree 从升序链表构建BST
0111 Minimum Depth of Binary Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 求二叉树的最短深度
0112 Path Sum BinaryTree DepthFirstSearch Tree 是否存在从根到叶节点值的和等于某值的路径
0114 Flatten Binary Tree to Linked List BinaryTree DepthFirstSearch LinkedList Stack Tree 把树压成链表
0116 Populating Next Right Pointers in Each Node BinaryTree BreadthFirstSearch DepthFirstSearch Tree 树的同一层结点横向连接起来
0118 Yanghui's Triangle Array DynamicProgramming 生成杨辉三角
0119 Yanghui's Triangle II Array DynamicProgramming 生成杨辉三角的某一行
0120 Triangle Array DynamicProgramming 计算三角形二维数列从上到下最小的路径和
0121 Best Time to Buy and Sell Stock Array DynamicProgramming 一次买卖交易获得的最大值
0122 Best Time to Buy and Sell Stock II Array Greedy 不限次数交易获得的最大值
0123 Best Time to Buy and Sell Stock III Array DynamicProgramming 至多两次交易获得的最大值
0130 Surrounded Regions Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 把被X包围的O换成X
0131 Palindrome Partitioning Backtracking DynamicProgramming String 求字符串拆分成回文字符串数组的所有可能性
0136 Single Number Array BitManipulation 找出数列中只出现一次的元素
0139 Word Break DynamicProgramming HashTable Memoization String Trie 单词是否能完美拆分成存在字典中的pattern
0141 Linked List Cycle HashTable LinkedList TwoPointers 判断链表是否有环
0142 Linked List Cycle II HashTable LinkedList TwoPointers 判断链表是否有环并找出环开始的地方
0144 Binary Tree Preorder Traversal BinaryTree DepthFirstSearch Stack Tree 前序遍历输出
0145 Binary Tree Postorder Traversal BinaryTree DepthFirstSearch Stack Tree 后序遍历输出
0146 LRU Cache Design DoublyLinkedList HashTable LinkedList 实现一个LRU缓存
0152 Maximum Product Subarray Array DynamicProgramming 找出所有元素乘积最大的子串
0155 Min Stack Design Stack 构建能快速返回最小值的栈
0162 Find Peak Element Array BinarySearch
0167 Two Sum II Array BinarySearch TwoPointers 递增数列中找出和为目标值的两个元素
0168 Excel Sheet Column Title Math String 把数字转化为excel列名
0169 Majority Element Array Counting DivideAndConquer HashTable Sorting 找到多数元素
0170 Two Sum III Data Structure Design Design HastTable 设计可以插入数据并判断存储中是否有和为给定值的数据对的数据结构
0171 Excel Sheet Column Number Math String 把excel列名转化为数字
0172 Factorial Trailing Zeroes Math 求n!的末尾0的个数
0173 Binary Search Tree Iterator BinarySearchTree BinaryTree Design Iterator Stack Tree 设计一个返回BST中序遍历元素的生成器
0174 Dungeon Game Array DynamicProgramming Matrix 地牢游戏求能到达终点所需的最少初始生命值
0187 Repeated DNA Sequences BitManipulation HashFunction HashTable RollingHash SlidingWindow String 找到至少出现两次的基因段
0188 Best Time to Buy and Sell Stock IV DynamicProgramming 至多K次交易获得的最大值
0190 Reverse Bits BitManipulation 字符串表示的二进制数取反
0191 Number of 1 Bits BitManipulation 字符串表示的二进制数中1的个数
0192 Word Frequency Shell 统计词出现个数
0193 Valid Phone Numbers Shell 从文本中找出合法的电话号码
0195 Tenth Line Shell 打印出文本的第10行
0198 House Robber DynamicProgramming 抢劫不相邻房屋获得的最大收益
0200 Number of Islands Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 找到有几个岛屿
0203 Remove Linked List Elements LinkedList Recursion 链表中删除特定值的元素
0204 Count Primes Array Enumeration Math NumberTheory 统计小于n的质数个数
0206 Reverse Linked List LinkedList Recursion 反转链表
0207 Course Schedule BreadthFirstSearch DepthFirstSearch Graph TopologicalSort 是否能顺利完成所有课程
0209 Minimum Size Subarray Sum Array BinarySearch TwoPointers 求和大于等于目标值的最短子串
0210 Course Schedule II BreadthFirstSearch DepthFirstSearch Graph TopologicalSort 如能完成所有课程给出完成顺序
0213 House Robber II DynamicProgramming 抢劫不相邻房屋获得的最大收益
0214 Shortest Palindrome HashFunction RollingHash String StringMatching 找到从字符串头开始最长的回文组
0215 Kth Largest Element in an Array Array DivideAndConquer Heap Quickselect Sorting 数列中寻找第k大元素
0217 Contains Duplicate Array HashTable Sorting 查看数列是否包含重复元素
0219 Contains Duplicate II Array HashTable SlidingWindow 查看数列是否包含重复元素且其距离小于k
0221 Maximal Square Array DynamicProgramming Matrix 计算矩阵中最大正方形的面积
0222 Count Complete Tree Nodes BinarySearch BinaryTree DepthFirstSearch Tree 数一颗Complete二叉树的结点个数
0224 Basic Calculator Math Recursion Stack String 实现一个基础的加减计算器
0225 Implement Stack using Queues Design Queue Stack 用queue来实现stack
0226 Invert Binary Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 二叉树元素镜像转置
0227 Basic Calculator II Math Stack String 实现一个基础的加减乘除计算器
0228 Summary Ranges Array 把递增数列中连续的数字用范围表示
0230 Kth Smallest Element in a BST BinaryTree BreadthFirstSearch DepthFirstSearch Tree 在BST中找到第k小的元素
0231 Power of Two BitManipulation Math Recursion 判断数是否为2的次方
0232 Implement Queue using Stacks Design Queue Stack 用stack来实现queue
0234 Palindrome Linked List LinkedList Recursion Stack TwoPointers 判断链表是否是回文
0235 Lowest Common Ancestor of a Binary Search Tree BinarySearchTree BinaryTree DepthFirstSearch Tree 找到BST中两个元素的LCA
0236 Lowest Common Ancestor of a Binary Tree BinaryTree DepthFirstSearch Tree 找到二叉树中两个元素的LCA
0238 Product of Array Except Self Array 返回数列所有元素乘积和除以各元素的数列
0239 Sliding Window Maximum Dequeue Heap SlidingWindow 返回定长的向右滑动的窗口每一步的局部最大值组成的数组
0241 Different Ways to Add Parentheses DynamicProgramming Math Memoization Recursion String 给算式任意位置添加括号得到的所有可能解
0242 Valid Anagram HastTable Sort 判断一个字符串是否为另一个的易位词
0252 Meeting Rooms Array Sorting 会议时间是否重合
0257 Binary Tree Paths BinaryTree DepthFirstSearch String Tree 打印出从根到叶子的所有路径
0259 3Sum Smaller Array TwoPointers 求数组中三元组和小于目标值的个数
0263 Ugly Number Math 判断一个数的质因数是否限定在2,3,5之中
0264 Ugly Number II DynamicProgramming HashTable Heap Math 求从1开始第n个题0263中描述的数字
0268 Missing Number Array BitManipulation HashTable Math Sorting 找出缺失元素
0278 First Bad Version BinarySearch Interactive 找到第一个坏版本
0279 Perfect Squares BreadthFirstSearch DynamicProgramming Math 把数分解为最短的平方和
0283 Move Zeroes Array TwoPointers 将数列中的0移到最后
0290 Word Pattern HashTable String 查看字符串是否按规律排列
0292 Nim Game Brainteaser GameTheory Math 拿走最后一个石子获胜的游戏
0295 Find Median from Data Stream DataStream Design Heap Sorting TwoPointers 数据流中求中位数
0297 Serialize and Deserialize Binary Tree BinaryTree BreadthFirstSearch DepthFirstSearch Design String Tree 序列化及反序列化一棵树
0300 Longest Increasing Subsequence Array BinarySearch DynamicProgramming 求最长的递增子数列长度
0304 Range Sum Query 2D - Immutable Array Design Matrix PrefixSum 计算矩阵中两点确定的一个矩形覆盖的元素之和
0305 Number of Islands II Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 填海造岛过程中岛屿个数
0309 Best Time to Buy and Sell Stock with Cooldown DynamicProgramming 不限次数交易获得的最大值,卖出后有一天冷却期
0310 Minimum Height Trees BreadthFirstSearch DepthFirstSearch Graph TopologicalSort 找到最矮的树
0313 Super Ugly Number Array DynamicProgramming HashTable Heap Math
0316 Remove Duplicate Letters Greedy MonotonicStack Stack String 保持相对顺序的前提下移除重复字母,并且字典序最小
0319 Bulb Switcher Math Brainteaser 开关灯游戏
0322 Coin Change Array BreadthFirstSearch DynamicProgramming 最少能用几枚硬币凑成目标数额
0325 Maximum Size Subarray Sum Equals k ??? 求和等于目标值的最长子串
0326 Power of Three Math Recursion 判断某数是否是3的次方
0337 House Robber III DepthFirstSearch DynamicProgramming Tree 抢劫树形排列不相邻房屋获得的最大收益
0338 Counting Bits BitManipulation DynamicProgramming 统计0到n每个数包含1的个数
0341 Flatten Nested List Iterator DepthFirstSearch Design Iterator Queue Stack Tree 实现一个iterator来扁平化输出一个嵌套的列表
0342 Power of Four BitManipulation Math Recursion 判断某数是否是4的次方
0343 Integer Break DynamicProgramming Math 数拆分后的因子的乘积最大值
0344 Reverse String Recursion String TwoPointers 将字符数组反转
0347 Top K Frequent Elements Array BucketSort Counting DivideAndConquer HashTable Heap Quickselect Sorting 返回前k个最常见的元素
0354 Russian Doll Envelopes Array BinarySearch DynamicProgramming Sorting 最多有多少小信封能塞进大信封
0355 Design Twitter Design HashTable Heap LinkedList 实现简单的推特应用
0371 Sum of Two Integers BitManipulation 位操作实现两数相加
0372 Super Pow DivideAndConquer Math 求大数的高次方
0373 Find K Pairs with Smallest Sums Array Heap 两个数列中找到和最小的k对元素
0378 Kth Smallest Element in a Sorted Matrix Array BinarySearch Heap Matrix Sorting 在行和列都是升序的矩阵中找到第k小的元素
0380 Insert Delete GetRandom O(1) Array Design HashTable Math Randomized 实现增删随机读的复杂度都为O(1)的数据结构
0382 Linked List Random Node LinkedList Math Randomized ReservoirSampling 随机均匀选取链表中的某结点
0384 Shuffle an Array Array Math Randomized 随机均匀地洗牌
0387 First Unique Character in a String Counting HashTable Queue String 找到第一个只出现一次的字符
0389 Find the Difference BitManipulation HastTable Sorting String 找出多余的一个字符
0392 Is Subsequence DynamicProgramming String TwoPointers 判断是否是子串
0407 Trapping Rain Water II BreadthFirstSearch Heap 计算三维地形的积水量
0410 Split Array Largest Sum Array BinarySearch DynamicProgramming Greedy 把数列切分成N个子数列,求令子数列和最大值最小化的方案
0414 Third Maximum Number Array Sorting 第三大的数字
0415 Add Strings String 以字符串形式表示的两数之和
0416 Partition Equal Subset Sum Array DynamicProgramming 求数组能否分成两个和相等的子集
0435 Non-overlapping Intervals Array DynamicProgramming Greedy Sorting 移除最少的区间使列表中的区间没有重叠
0438 Find All Anagrams in a String HastTable 在字符串A中找到所有字符串B的易位词
0441 Arranging Coins BinarySearchTree Math 用硬币填满阶梯
0445 Add Two Numbers II LinkedList 以链表形式表示的两数之和
0448 Find All Numbers Disappeared in an Array Array HashTable 找到所有缺失的数
0449 Serialize and Deserialize BST BinarySearchTree BinaryTree BreadthFirstSearch DepthFirstSearch Design String Tree 序列化反序列化BST
0450 Delete Node in a BST BinarySearchTree BinaryTree Tree 在BST中删除一个结点
0451 Sort Characters By Frequency BucketSort Counting HashTable Heap Sorting String 按字符出现的频率降序排列字符串
0452 Minimum Number of Arrows to Burst Balloons Array Greedy Sorting 射出最少的箭穿破所有气球
0454 4Sum II BinarySearch HastTable 四个数列中分别取一个数q之和等于0的四元组个数
0455 Assign Cookies Array Greedy Sorting 分配饼干
0459 Repeated Substring Pattern String 检查字符串是否由某个子串重复n次构成
0460 LFU Cache Design DoublyLinkedList HashTable LinkedList 实现一个LFU缓存
0463 Island Perimeter Array BreadthFirstSearch DepthFirstSearch Matrix 计算岛屿的周长
0473 Matchsticks to Square Array Backtracking BitManipulation Bitmask DynamicProgramming 能否把火柴棍拼成正方形
0474 Ones and Zeroes DynamicProgramming 字符串表示的二进制数组中,找出最大的包含至多m个0和n个1的子集合
0476 Number Complement BitManipulation 求数的二进制反转
0494 Target Sum Array Backtracking DynamicProgramming 数列中的数字可以取正负,求其和可以等于目标值的组合数
0495 Teemo Attacking Array Simulation 计算进入异常状态的时间
0496 Next Greater Element I Array HashTable MonotonicStack Stack 找到下一个大于自己的元素
0502 IPO Array Greedy Heap Sorting 完成k个项目可以获得的最大纯利润
0503 Next Greater Element II Array MonotonicStack Stack 首尾循环的列表寻找下一个大于自己的元素
0504 Base 7 Math 十进制转七进制
0506 Relative Ranks Array Heap Sorting 把分数转换为名次
0509 Fibonacci Number DynamicProgramming Math Memoization 斐波那契数列
0516 Longest Palindromic Subsequence DynamicProgramming String 求最长回文子序列
0518 Coin Change 2 Array DynamicProgramming 求用不同面值硬币能凑出给定总额的方法数
0523 Continuous Subarray Sum DynamicProgramming Math 求是否有一个长度至少为2的子串其和为给定值的倍数
0528 Random Pick with Weight BinarySearch Math PrefixSum Randomized 按照权重随机选取元素
0530 Minimum Absolute Difference in BST BinarySearchTree BinaryTree BreadthFirstSearch DepthFirstSearch Tree BST中搜索两个结点差的最小值
0538 Convert BST to Greater Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 结点的值更新为整棵树所有大于等于该结点的值的和
0543 Diameter of Binary Tree BinaryTree DepthFirstSearch Tree 计算相距最远的两个结点的距离
0547 Number of Provinces BreadthFirstSearch DepthFirstSearch Graph UnionFind 统计有几个城市群
0560 Subarray Sum Equals K Array HashTable 求和为目标值的子串个数
0567 Permutation in String TwoPointer SlidingWindow 求字符串A是否包含字符串B的变种
0572 Subtree of Another Tree BinaryTree DepthFirstSearch HashFunction StringMatching Tree 判断一棵树是否为另一棵的子树
0583 Delete Operation for Two Strings String DynamicProgramming 求令两个字符串相等需要的删除操作数
0600 Non-negative Integers without Consecutive Ones DynamicProgramming 从0到给定值之间所有数的二进制表示中没有连续1的数的个数
0628 Maximum Product of Three Numbers Array Math 数列中挑选三个数使其乘积最大
0632 Smallest Range Covering Elements from K Lists HashTable String TwoPointers 找到一个最小范围覆盖所有K个数列中至少一个元素
0638 Shopping Offers Array Backtracking BitManipulation Bitmask DynamicProgramming Memoization 在存在商品促销的情况下计算购买需要物资的最小花费
0645 Set Mismatch Array BitManipulation HashTable Sorting 集合中找出出现两次的元素和缺少的元素
0652 Find Duplicate Subtrees BinaryTree BreadthFirstSearch DepthFirstSearch Tree 寻找重复的子树
0653 Two Sum IV Input Is A BST Tree 在BST中找到等于目标值的两个数
0654 Maximum Binary Tree Array BinaryTree DivideAndConquer MonotonicStack Stack Tree 按要求构建二叉树
0657 Robot Return to Origin Simulation String 判断机器人经过一系列指令后能否回到原点
0659 Split Array into Consecutive Subsequences Array Greedy HashTable Heap 能否将数组分成数个递增的子数组
0684 Redundant Connection BreadthFirstSearch DepthFirstSearch Graph UnionFind 移除多余的边使带环的图成为树
0686 Repeated String Match String a字符串重复多少次可以包含b字符串
0689 Maximum Sum of 3 Non-Overlapping Subarrays Array DynamicProgramming 找到三个指定长度的和最大的独立子串
0692 Top K Frequent Words BucketSort Counting HashTable Heap Sorting String Trie 出现频率最高的k个词
0693 Binary Number with Alternating Bits BitManipulation 判断数的二进制表示是否为0和1相间
0695 Max Area of Island Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 找到最大的岛
0697 Degree of an Array Array 找到和字符串有相同度的子串
0698 Partition to K Equal Sum Subsets Array Backtracking BitManipulation Bitmask DynamicProgramming Memoization 能否把集合分成k个和相等的子集
0700 Search in a Binary Search Tree BinarySearchTree BinaryTree Tree 在BST中搜索一个元素
0701 Insert into a Binary Search Tree BinarySearchTree BinaryTree Tree 在BST中插入一个元素
0703 Kth Largest Element in a Stream BinarySearchTree BinaryTree DataStream Design Heap Tree 不断插入新元素同时找到第k大的元素
0704 Binary Search Array BinarySearch 二分搜索元素
0710 Random Pick with Blacklist BinarySearch HashTable Math Randomized Sorting 随机返回数列中除黑名单以外的元素
0712 Minimum ASCII Delete Sum for Two Strings String DynamicProgramming 删除字母使字符串相等,求删除的字母ASCII值最小
0713 Subarray Product Less Than K Array TwoPointers 乘积小于目标值的子串的个数
0714 Best Time to Buy and Sell Stock with Transaction Fee Array DynamicProgramming Greedy 不限次数交易获得的最大值,每笔交易有手续费
0718 Maximum Length of Repeated Subarray Array BinarySearch DynamicProgramming HashTable 寻找最大公共子串
0724 Find Pivot Index Array 找到左边所有元素和等于右边所有元素和的index
0727 Minimum Window Subsequence DynamicProgramming HashTable SlidingWindow String TwoPointers 字符串A中找到最短的可以包含字符串B的子串
0739 Daily Temperatures Array MonotonicStack Stack 求等待几天可以比今天更热
0740 Delete and Earn DynamicProgramming 在数组中取一个数可得分,但是要删除它和如果存在的它+-1的值,求最大得分
0743 Network Delay Time BreadthFirstSearch DepthFirstSearch Graph Heap ShortestPath 从一个点出发遍历所有网络需要花费的时间
0746 Min Cost Climbing Stairs Array DynamicProgramming 计算爬上阶梯需要的最小精力
0752 Open the Lock Array BreadthFirstSearch HashTable String 密码锁至少需要转动几下才能打开
0763 Partition Labels Greedy HashTable String TwoPointers 尽可能将字符串分段,且每个字母仅出现在某段中
0772 Basic Calculator III Math Stack String 实现一个基础的加减乘除计算器
0773 Sliding Puzzle Array BreadthFirstSearch Matrix 滑块游戏
0774 Minimize Max Distance to Gas Station Array BinarySearch 插入K个加油站,找到两个加油站之间最大距离的最小值
0783 Minimum Distance Between BST Nodes BinarySearchTree BinaryTree BreadthFirstSearch DepthFirstSearch Tree BST中搜索两个结点差的最小值
0784 Letter Case Permutation Backtracking BitManipulation String alnum字符串中字母大小写变换的排列组合
0785 Is Graph Bipartite? BreadthFirstSearch DepthFirstSearch Graph UnionFind 能否把结点分为两组,使每条边的两边的结点分属两个组
0787 Cheapest Flights Within K Stops BreadthFirstSearch DepthFirstSearch DynamicProgramming Graph Heap ShortestPath 求转机k次以内两地间最便宜的花费
0793 Preimage Size of Factorial Zeroes Function Math BinarySearch 求阶乘值的末尾有k个0的数的个数
0796 Rotate String String StringMatching 判断一个字符串是否是另一个字符串shift后的形态
0797 All Paths From Source to Target Backtracking BreadthFirstSearch DepthFirstSearch Graph 找到DAG中起点到终点的所有路径
0827 Making A Large Island Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 海中最多填一个土能造出的最大岛
0870 Advantage Shuffle Array Greedy Sorting 交换数列中的元素使其对另一个数列逐元素比较大小占据最大优势
0875 Koko Eating Bananas Array BinarySearch 求在规定时间内吃完所有香蕉堆的最小进食速度
0876 Middle of the Linked List LinkedList TwoPointers 寻找链表的中点
0877 Stone Game Array DynamicProgramming GameTheory Math 拿石头堆的游戏
0887 Super Egg Drop BinarySearch DynamicProgramming Math 找到扔下鸡蛋刚好不会碎的楼层数需要的最少尝试次数
0895 Maximum Frequency Stack Design HashTable OrderedSet Stack 实现一个Pop最大出现频率的值的栈
0912 Sort an Array Array BucketSort CountingSort DivideAndConquer Heap MergeSort RadixSort Sorting 给数列排序
0921 Minimum Add to Make Parentheses Valid Greedy Stack String 添加最小的括号数时括号合法成对
0931 Minimum Falling Path Sum Array DynamicProgramming Matrix 求坠落路径上数值之和最小的路径
0938 Range_Sum_of_BST BinarySearchTree BinaryTree DepthFirstSearch Tree 范围内BST节点值的和
0954 Array of Doubled Pairs Array Greedy Hashtable Sorting 判断数列是否由另一个数列和其两倍数列构成
0969 Pancake Sorting Array Greedy Sorting TwoPointers 煎饼排序
0974 Subarray Sums Divisible by K Array HashTable 和可以整除目标值的子串的个数
0977 Squares of a Sorted Array Array Sorting TwoPointers 求排好序的数组各元素平方后得到的新升序数组
0978 Longest Turbulent Subarray Array DynamicProgramming SlidingWindow 找到符合峰谷交替规律的最长的子串
0983 Minimum Cost For Tickets Array DynamicProgramming 如何买票最省钱
0986 Interval List Intersections Array TwoPointers 两个区间组成的列表找交集
0989 Add to Array-Form of Integer Array 求一个以数组形式表示的数和一个整数之和
0990 Satisfiability of Equality Equations Array Graph String UnionFind 判断等式集合是否存在矛盾
1009 Complement of Base 10 Integer BitManipulation 求数的二进制反转
1011 Capacity To Ship Packages Within D Days Array BinarySearch Greedy 求在规定的天数内能装完所有货物的最小的船的容量
1023 Camelcase Matching String StringMatching Trie TwoPointers 字符串匹配
1024 Video Stitching Array DynamicProgramming Greedy 拼接一段完整视屏需要的最少数量的片段
1038 Binary Search Tree to Greater Sum Tree BinaryTree BreadthFirstSearch DepthFirstSearch Tree 结点的值更新为整棵树所有大于等于该结点的值的和
1049 Last Stone Weight II Array DynamicProgramming 求石头互相碰撞湮灭后剩余重量的最小值
1081 Smallest Subsequence of Distinct Characters Greedy MonotonicStack Stack String 保持相对顺序的前提下移除重复字母,并且字典序最小
1099 Two Sum Less Than K Array 数组中找到小于目标值的最大两数之和
1109 Corporate Flight Bookings Array PrefixSum 从订单中统计各航班座位预定总数
1143 Longest Common Subsequence DynamicProgramming String 求最长公共子数列
1201 Ugly Number III BinarySearch Math NumberTheory
1235 Maximum Profit in Job Scheduling Array BinarySearch DynamicProgramming Sorting 在时间段不冲突的前提下接受任务的最大利润
1288 Remove Covered Intervals Array Sorting 移除能被另一个区间覆盖的区间
1306 Jump Game III BreadthFirstSearch DepthFirstSearch Recursion 从给定的出发点允许向前向后跳跃,判断是否能到终点
1340 Jump Game V DynamicProgramming 从任意点出发允许向前向后最远跳d的距离且只能从大数跳向小数,求最多能覆盖几个index |
1345 Jump Game IV BreadthFirstSearch 从头开始,每一条可以向前向后一格,或传送到其他值相等的index,求到达终点最少的跳跃次数
1353 Maximum Number of Events That Can Be Attended Array Greedy Heap 最多可以参加几个活动
1373 Maximum Sum BST in Binary Tree BinarySearchTree BinaryTree DepthFirstSearch DynamicProgramming Tree 找到和最大的BST子树
1392 Longest Happy Prefix HashFunction RollingHash String StringMatching KMP算法的应用
1408 String Matching in an Array String StringMatching 在一组字符串中找出所有能成为其他字符串的子串的串
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence String StringMatching 找到以某个pattern为前缀的词的序号
1514 Path with Maximum Probability Graph Heap ShortestPath 找到到达终点成功率最高的路径
1541 Minimum Insertions to Balance a Parentheses String Greedy Stack String 添加最小的括号数时括号合法成对
1590 Make Sum Divisible by P Array BinarySearch HashTable Math 字符串中删除最小的子串使剩下的元素和可以整除目标值
1615 Maximal Network Rank Graph 图中两个节点出度和的最大值
1631 Path With Minimum Effort Array BinarySearch BreadthFirstSearch DepthFirstSearch Heap Matrix UnionFind 寻找一条消耗体力最少的登山路径
1636 Sort Array by Increasing Frequency Array HashTable Sorting 按照元素出现的频率对字符串升序排序,如果频率相同则按数字大小降序排列
1646 Get Maximum in Generated Array Array DynamicProgramming Simulation 获得一个自生成数列的最大值
1658 Minimum Operations to Reduce X to Zero BinarySearch Greedy SlidingWindow TwoPointers 每一步可以移除字符串头或尾的元素,目标值减去该元素,求将目标值减为0的最少步数
1668 Maximum Repeating Substring String StringMatching 保持作为某字符串子串的前提下pattern自身最多能重复多少次
1679 Max Number of K-Sum Pairs HashTable 数组中每一步可以移除和为K的两个元素,求最大可执行次数
1695 Maximum_Erasure_Value TwoPointers 找到不含重复元素的且和为最大的子串
1696 Jump Game VI Dequeue 从头出发,每次最远可以前进k,求到终点经过的index对应的值之和的最大值
1711 Count Good Meals Array HashTable TwoPointers 数列中和为2的次方的二元组的数量
1749 Maximum Absolute Sum of Any Subarray Greedy 和的绝对值最大的子串
1751 Maximum Number of Events That Can Be Attended II Array BinarySearch DynamicProgramming 在次数限制内最多可以参加几个活动
1764 Form Array by Concatenating Subarrays of Another Array Array Greedy StringMatching
1786 Number of Restricted Paths From First to Last Node DynamicProgramming Graph Heap ShortestPath TopologicalSort 起点到终点之间的有条件的路径数
1791 Find Center of Star Graph Graph 找出星型图的中点
1871 Jump Game VII BreadthFirstSearch Greedy LineSweep 从一个01字符串的头部出发,每次可以前进的距离介于[i,j]之间,且只能落在值为0的index上,求是否可以到达终点
1891 Cutting Ribbons Array BinarySearch 切割一些绳子获得k条相同长度的绳子,求其长度的最大值
1903 Largest Odd Number in String Greedy Math String 找出字符串中最大的奇数
1905 Count Sub Islands Array BreadthFirstSearch DepthFirstSearch Matrix UnionFind 统计子岛的数量
1928 Minimum Cost to Reach Destination in Time DynamicProgramming Graph 在规定时间内到达目的地的最小花费
1961 Check If String Is a Prefix of Array Array String
1962 Remove Stones to Minimize the Total Array Heap
1971 Find if Path Exists in Graph BreadthFirstSearch DepthFirstSearch Graph 判断图中两点是否有通路
1976 Number of Ways to Arrive at Destination DynamicProgramming Graph ShortestPath TopologicalSort 到达终点最短的距离的路径数
1984 Minimum Difference Between Highest and Lowest of K Scores Array SlidingWindow Sorting
1985 Find the Kth Largest Integer in the Array Array String DivideAndConquer Heap Quickselect Sorting 数列中寻找第k大元素
1992 Find All Groups of Farmland Array BreadthFirstSearch DepthFirstSearch Matrix
1995 Count Special Quadruplets Array Enumeration 统计前三个元素和等于第四个元素的四元组数目
1996 The Number of Weak Characters in the Game Array Greedy MonotonicStack Sorting Stack 找出元组中值严格小于其他元组的数量
2000 Reverse Prefix of Word String TwoPointers 反转单词的前缀
2006 Count Number of Pairs With Absolute Difference K Array Counting HashTable 计算差正好为k的元素对
2007 Find Original Array From Doubled Array Array Greedy Hashtable Sorting 判断数列是否由另一个数列和其两倍数列构成并返回单倍数列
2008 Maximum Earnings From Taxi Array BinarySearch DynamicProgramming Sorting 出租车计算载客利润最大值
2011 Final Value of Variable After Performing Operations Array Simulation String
2012 Sum of Beauty in the Array Array
2016 Maximum Difference Between Increasing Elements Array
2017 Grid Game Array Matrix PrefixSum
2022 Convert 1D Array Into 2D Array Array Matrix Simulation 把一维数组转化为m*n的矩阵
2024 Maximize the Confusion of an Exam BinarySearch PrefixSum SlidingWindow String
2028 Find Missing Observations Array Math Simulation
2032 Two Out of Three Array HashTable
2033 Minimum Operations to Make a Uni-Value Grid Array Math Matrix Sorting
2039 The Time When the Network Becomes Idle Array BreadthFirstSearch Graph 计算网络中最早何时没有数据包流通
2049 Count Nodes With the Highest Score Array BinaryTree DepthFirstSearch Tree
2054 Two Best Non-Overlapping Events Array BinarySearch DynamicProgramming Heap Sorting 找到权重和最大的不重叠的两段事件
2063 Vowels of All Substrings Combinatorics DynamicProgramming Math String 所有子字符串中元音出现的次数
2075 Decode the Slanted Ciphertext String Simulation 解码斜对角加密字符串
2087 Minimum Cost Homecoming of a Robot in a Grid Array Greedy Matrix 机器人以最小的代价回家
2089 Find Target Indices After Sorting Array Array BinarySearch Sorting 找出目标在排序后的数列中坐标
2090 K Radius Subarray Averages Array SlidingWindow 计算数列中每个元素周围一定半径之内元素的平均值
2091 Removing Minimum and Maximum From Array Array Greedy 数列中移除最大和最小值需要的操作数
2092 Find All People With Secret BreadthFirstSearch DepthFirstSearch Graph Sorting UnionFind 列出所有知道秘密的人
2095 Delete the Middle Node of a Linked List LinkedList TwoPointers 删除链表中间位置的节点
2100 Find Good Days to Rob the Bank Array DynamicProgramming PrefixSum 数列中寻找一个值的谷底
2103 Rings and Rods HashTable String 统计套有三种颜色圆环的的杆子数量
2106 Maximum Fruits Harvested After at Most K Steps Array BinarySearch PrefixSum SlidingWindow 在一定步数内收获最多的果实
2109 Adding Spaces to a String Array Simulation String 在字符串中插入空格
2114 Maximum Number of Words Found in Sentences Array String 找到单词最多的句子
2115 Find All Possible Recipes from Given Supplies Array Graph HashTable String TopologicalSort 由指定的素材找出所有可以做的菜
2116 Check if a Parentheses String Can Be Valid Greedy Stack String 检查括号是否能成对
2119 A Number After a Double Reversal Math 数在两次反转后是否保持原来的值
2120 Execution of All Suffix Instructions Staying in a Grid Simulation String 求从指令集任意位置执行机器人可以行走的最远距离
2121 Intervals Between Identical Elements Array HashTable PrefixSum 求数列中相同元素之间的距离差之和
2124 Check if All A's Appears Before All B's String 检查是否所有A在B之前
2125 Number of Laser Beams in a Bank Array Math Matrix String 统计镭射数量
2126 Destroying Asteroids Array Greedy Sorting 是否能毁灭所有小行星
2127 Maximum Employees to Be Invited to a Meeting DepthFirstSearch Graph TopologicalSort 出席圆桌会议的最大人数
2129 Capitalize the Title String 首字母大写
2130 Maximum Twin Sum of a Linked List LinkedList Stack TwoPointers 求链表中对称位置的节点和的最大值
2132 Stamping the Grid Array Greedy Matrix PrefixSum 是否可以用一个矩形邮戳盖满矩阵中的空格且不触碰已标记过的格子
2133 Check if Every Row and Column Contains All Numbers Array HashTable Matrix 检查n*n矩阵每一行每一列都包含了1到n的所有数字
2134 Minimum Swaps to Group All 1's Together II Array SlidingWindow 把所有1凑到一起需要的swap数
2135 Count Words Obtained After Adding a Letter Array BitManipulation HashTable Sorting String 求目标字符串可以从初始字符串加一个字符并改变顺序而得到的树木
2136 Earliest Possible Day of Full Bloom Array Greedy Sorting 所有种子开花的最早日期
2140 Solving Questions With Brainpower Array DynamicProgramming 解决问题获得最大收益
2144 Minimum Cost of Buying Candies With Discount Array Greedy Sorting 利用折扣买完所有糖所需的最小花费
2145 Count the Hidden Sequences Array Prefix 通过差分数列和元素值的上下限计算可能的原数列的数量
2149 Rearrange Array Elements by Sign Array Simulation TwoPointers 按照一正一负顺序重排数列
2150 Find All Lonely Numbers in the Array Array Counting HashTable 数列中找到所有孤独元素
2155 All Divisions With the Highest Score of a Binary Array Array 求分割数列使得分最高的所有index
2156 Find Substring With Given Hash Value HashFunction RollingHash SlidingWindow String
2164 Sort Even and Odd Indices Independently Array Sorting 将奇偶位置的数列分别升降序排列
2165 Smallest Value of the Rearranged Number Math Sorting 重新排列数字可以取到的最小值
2169 Count Operations to Obtain Zero Math Simulation 两个数相减需要几次操作才能得到0
2171 Removing Minimum Number of Magic Beans Array 移除最少的豆子使非空袋子中的豆子数相等
2177 Find Three Consecutive Integers That Sum to a Given Number Math Simulation 判断数能否拆分成三个连续的整数
2187 Minimum Time to Complete Trips Array BinarySearch 完成目标行程数所需的最小时间
2181 Merge Nodes in Between Zeros LinkedList 将链表中两个值为0的节点之间的非零节点合并为一个节点重构链表

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL