算法
文章平均质量分 69
算法 实战
AI架构师易筋
工作10+年,AI方向架构师,曾经任职阿里巴巴,世界500强HSBC。擅长架构、深度学习、Transformer、CNN、NLP、算法、数据结构、设计模式、iOS、Java Spring Boot, Spring Cloud。易筋乃阿里巴巴花名。
展开
-
算法导论 高频算法题 数据结构与算法之美
说明业务开发工程师,你真的愿意做一辈子 CRUD Boy吗?基础架构研发工程师,写出达到开源水平的框架才是你的目标!对编程还有追求?不想被行业淘汰?那就不要只会写凑合能用的代码!之前花了1年时间学完《算法导论》,实际上里面有很多数学公式,微积分,概率,举证,和归纳法,学起来确实投入很多时间。知名论坛一亩三分地,推荐《Cracking the Coding Interview》太贵. L...原创 2019-02-20 10:31:38 · 1004 阅读 · 0 评论 -
算法: 求数幂n次方50. Pow(x, n)
【代码】算法: 求数幂n次方50. Pow(x, n)原创 2023-10-05 16:36:51 · 123 阅读 · 0 评论 -
算法: 对位置变换的字符串分组 49. Group Anagrams
这段代码的核心思想是使用一个固定长度的计数列表来表示每个字符串,该列表中的每个元素都表示字符串中相应字母的出现次数。这是因为我们需要遍历每个字符串,并对每个字符串的每个字符进行排序,排序的时间复杂度是 O(KlogK)。这段代码的核心思想是利用字母异位词排序后相等的特性,将排序后的字符串作为字典的键,将原字符串添加到对应的列表中,从而实现分组。时间复杂度:O(NK),其中 N 是字符串的数量,K 是字符串的最大长度。如果 c 是 ‘b’,那么。的结果是 1,表示 ‘b’ 是字母表中的第二个字母,依此类推。原创 2023-09-29 09:56:45 · 360 阅读 · 0 评论 -
算法: 随机选择相同数字的索引398. Random Pick Index
与普通的字典不同,defaultdict 允许你为字典中不存在的键提供一个默认值。这样,当你尝试访问一个不存在的键时,defaultdict 会自动为该键创建一个条目,并将其设置为你提供的默认值。这是因为在最坏的情况下,nums 中的每个数字都是唯一的,因此我们需要为每个数字存储一个索引。使用 defaultdict 可以让代码更简洁,减少了检查键是否存在的需要,从而提高代码的可读性和效率。pick 方法:O(1),因为我们只是从一个已知长度的列表中随机选择一个元素。原创 2023-08-26 23:32:40 · 250 阅读 · 0 评论 -
算法: 4数之和到k数之和通用解法18. 4Sum
解决“4数之和”问题,即寻找四个数字,使它们的和等于目标值。它使用了更一般的kSum函数来解决k数之和问题,并使用了一个特定的twoSum函数来处理2数之和的特例。所以,整体时间复杂度是O(nlogn) + O(n^k),在这种特定情况下,k=4,所以复杂度是O(nlogn + n。空间复杂度为O(n)(由于递归调用和seen集合的存储)。原创 2023-08-10 23:17:16 · 182 阅读 · 0 评论 -
算法: 将整数转换为罗马数字12. Integer to Roman
所以时间复杂度是 O(1)。尽管我们在每次迭代中都会执行乘法和字符串连接操作,这两种操作的复杂度都是 O(k),其中 k 是需要重复的次数。在代码 ‘’.join(res) 中,join() 方法用于连接序列 res 中的元素,其中的 ‘’(空字符串)表示连接的字符。结果列表的长度最多为15(考虑到数字1994,对应的罗马数字为 “MCMXCIV”,长度为7),所以空间复杂度也是 O(1)。Python中的 join() 方法是一个字符串方法,它用于将序列中的元素以特定的字符连接生成一个新的字符串。原创 2023-07-28 08:36:43 · 148 阅读 · 0 评论 -
算法: 没有重复字符的最长字符串3. Longest Substring Without Repeating Characters
没有重复字符的最长字符串3. Longest Substring Without Repeating Characters原创 2023-07-25 00:02:19 · 114 阅读 · 0 评论 -
算法: 插入和合并间隔57. Insert Interval
【代码】算法: 插入和合并间隔57. Insert Interval。原创 2023-07-20 00:31:47 · 69 阅读 · 0 评论 -
算法:合并间隔56. Merge Intervals
排序后的列表按照子列表的第一个元素从小到大排列。这种排序可以用于根据区间的起始位置对区间进行排序,以便进一步处理或分析。这段代码使用了Python中的sort()方法对列表intervals进行排序,排序的依据是每个子列表的第一个元素。lambda表达式是一种匿名函数的简写形式,它允许我们在代码中创建小型的、一次性的函数,无需显式地定义函数名称。Lambda表达式在需要简单、临时的函数定义时非常有用,可以减少代码的复杂性和冗余,提高可读性和编写效率。定义了一个简单的加法函数,将两个参数相加并返回结果。原创 2023-07-17 23:12:20 · 288 阅读 · 0 评论 -
算法: 递归生成成对的括号22. Generate Parentheses
【代码】算法: 递归生成成对的括号22. Generate Parentheses。原创 2023-07-05 23:28:39 · 135 阅读 · 0 评论 -
算法: 不用排序如何解决3数之和15. 3Sum
j, i!= k, and j!思路分析:降维处理,3 Sum可以降维为2 Sum,简单的过滤重复为先排序,然后用双指针或者用set来过滤重复的值。原创 2023-07-03 23:14:03 · 260 阅读 · 0 评论 -
算法: 移除单链表的倒数第N个节点 19. Remove Nth Node From End of List
【代码】算法: 移除单链表的倒数第N个节点 19. Remove Nth Node From End of List。原创 2023-07-03 23:10:12 · 623 阅读 · 0 评论 -
算法: 最长回文子字符串5. Longest Palindromic Substring
Given a string s, return the longestpalindromicsubstringin s.Example 1:Example 2:Constraints:原创 2023-06-26 07:56:31 · 93 阅读 · 0 评论 -
算法: 链表模仿整数相加2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.You may assume the two number原创 2023-06-25 11:25:38 · 64 阅读 · 0 评论 -
算法:分区列表86. Partition List
【代码】算法:分区列表86. Partition List。原创 2023-06-24 15:47:04 · 865 阅读 · 0 评论 -
146. LRU Cache最近最少使用 (LRU) 缓存 Least Recently Used (LRU) cache.
【代码】146. LRU Cache最近最少使用 (LRU) 缓存 Least Recently Used (LRU) cache.原创 2023-06-20 00:19:37 · 1270 阅读 · 0 评论 -
LeetCode: 最长连续序列128. Longest Consecutive Sequence
【代码】LeetCode: 最长连续序列128. Longest Consecutive Sequence。原创 2023-06-18 17:36:40 · 44 阅读 · 0 评论 -
算法: 145. 后序遍历二叉树Binary Tree Postorder Traversal
145. 后序遍历二叉树Binary Tree Postorder Traversal原创 2022-11-30 01:13:37 · 215 阅读 · 0 评论 -
算法: 144. 二叉树前序遍历Binary Tree Preorder Traversal
算法: 144. 二叉树前序遍历Binary Tree Preorder Traversal原创 2022-11-29 02:00:43 · 277 阅读 · 0 评论 -
算法: 零一背包问题416. Partition Equal Subset Sum
这个问题本质上是让我们找出一个集合中是否有几个数字能够和一个特定的值(在这个问题中,该值是。背包问题,对于每个数字,我们可以选择或不选择。组成,其余由其他之前的数字组成。转移函数:对于每个数字,如果我们不选择它,(零个数 总和 0 为真)个数字中得到特定的和。中挑选出这样一个和为。原创 2022-10-31 19:20:48 · 832 阅读 · 0 评论 -
Google面试题原理解析 12个乒乓球其中有1个次品,用天平称重3次找出
在12个小球里有一个次品,重量与其他11个球不同。用一个没有砝码的天平,称3次,保证找到那个次品,并且区分出次品是轻还是重呢?”这个问题看似简单,做起来还真不容易。误区也许有人说我可以用二分法,先把球均分成两堆,上天平比较,找到重的一堆,次品就在这里。再把重的一堆均分成两堆,上天平比较…这样,每次就能把球去掉一半,就能最快找到次品啦!这样子会很慢。...原创 2022-07-22 08:40:35 · 7733 阅读 · 2 评论 -
算法: 编辑距离使得单词相同 72. Edit Distance
算法: 编辑距离使得单词相同 72. Edit Distance原创 2022-06-28 22:29:31 · 159 阅读 · 0 评论 -
算法: 求和377. Combination Sum IV
Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.The test cases are generated so that the answer can fit in a 32-bit integer.Example 1:Note that different sequences are原创 2022-06-20 08:35:35 · 141 阅读 · 0 评论 -
343. 求分解整数的乘积最大化Integer Break
343. Integer BreakGiven an integer n, break it into the sum of k positive integers, where k >= 2, and maximize the product of those integers.Return the maximum product you can get.Example 1:Input: n = 2Output: 1Explanation: 2 = 1 + 1, 1 × 1 = 1.原创 2022-04-20 22:46:37 · 217 阅读 · 0 评论 -
算法: 1和0子集合的个数 474. Ones and Zeroes
474. Ones and ZeroesYou are given an array of binary strings strs and two integers m and n.Return the size of the largest subset of strs such that there are at most m 0’s and n 1’s in the subset.A set x is a subset of a set y if all elements of x are al原创 2022-03-26 08:42:15 · 214 阅读 · 0 评论 -
算法: 数组是否可以分成和相等的两个子集416. Partition Equal Subset Sum
416. Partition Equal Subset SumGiven a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Example 1:Input: nums = [1,5,11,5]Output: trueE原创 2022-03-17 08:08:33 · 260 阅读 · 0 评论 -
算法: 硬币找零 II 518. Coin Change 2
518. Coin Change 2You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.Return the number of combinations that make up that amount. If that amount of money cannot be原创 2022-03-14 22:03:21 · 353 阅读 · 0 评论 -
算法: 硬币找零322. Coin Change
322. Coin ChangeYou are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money.Return the fewest number of coins that you need to make up that amount. If that amount of money原创 2022-03-13 23:31:22 · 242 阅读 · 0 评论 -
算法: 使用交易费买卖股票的最佳时机714. Best Time to Buy and Sell Stock with Transaction Fee
714. Best Time to Buy and Sell Stock with Transaction FeeYou are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.Find the maximum profit you can achieve. You may comple原创 2022-03-11 22:27:45 · 224 阅读 · 0 评论 -
算法: 冷却时间买卖股票的最佳时机309. Best Time to Buy and Sell Stock with Cooldown
309. Best Time to Buy and Sell Stock with CooldownYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete as many transactions as you like (i.e., buy one and sel原创 2022-03-09 22:12:28 · 247 阅读 · 0 评论 -
算法: 买卖股票的最佳时机 III123. Best Time to Buy and Sell Stock III
123. Best Time to Buy and Sell Stock IIIYou are given an array prices where prices[i] is the price of a given stock on the ith day.Find the maximum profit you can achieve. You may complete at most two transactions.Note: You may not engage in multiple tr原创 2022-03-08 22:01:03 · 239 阅读 · 0 评论 -
算法: 买卖股票的最佳时机 IV 188. Best Time to Buy and Sell Stock IV
188. Best Time to Buy and Sell Stock IVYou are given an integer array prices where prices[i] is the price of a given stock on the ith day, and an integer k.Find the maximum profit you can achieve. You may complete at most k transactions.Note: You may no原创 2022-03-07 22:46:39 · 162 阅读 · 0 评论 -
算法: 最大乘积子数组152. Maximum Product Subarray
152. Maximum Product SubarrayGiven an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product.The test cases are generated so that the answer will fit in a 32-bit integer.A subarray原创 2022-02-27 22:48:31 · 414 阅读 · 0 评论 -
算法: 二叉树右侧视图199. Binary Tree Right Side View
199. Binary Tree Right Side ViewGiven the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.Example 1:Input: root = [1,2,3,null,5,null,4]Output: [1,3,4]Exa原创 2022-02-21 09:39:59 · 352 阅读 · 0 评论 -
算法: 二叉树级顺序遍历 (3种解法)102. Binary Tree Level Order Traversal
102. Binary Tree Level Order TraversalGiven the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level).Example 1:Input: root = [3,9,20,null,null,15,7]Output: [[3],[9,20],[15,7]]Exampl原创 2022-02-20 23:20:19 · 519 阅读 · 0 评论 -
算法: 等分子集总和416. Partition Equal Subset Sum
416. Partition Equal Subset SumGiven a non-empty array nums containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Example 1:Input: nums = [1,5,11,5]Output: trueE原创 2021-12-31 17:40:39 · 381 阅读 · 0 评论 -
算法: 超级落蛋计算第一次蛋碎的楼层887. Super Egg Drop
887. Super Egg DropYou are given k identical eggs and you have access to a building with n floors labeled from 1 to n.You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg原创 2021-12-17 08:06:01 · 217 阅读 · 0 评论 -
算法: 最长递增子序列300. Longest Increasing Subsequence
300. Longest Increasing SubsequenceGiven an integer array nums, return the length of the longest strictly increasing subsequence.A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of t原创 2021-12-16 10:26:34 · 4161 阅读 · 0 评论 -
算法: 求矩形框数字之和304. Range Sum Query 2D - Immutable
304. Range Sum Query 2D - ImmutableGiven a 2D matrix matrix, handle multiple queries of the following type:Calculate the sum of the elements of matrix inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2)原创 2021-12-15 08:05:37 · 363 阅读 · 0 评论 -
算法: 不可变数组范围总和查询303. Range Sum Query - Immutable
303. Range Sum Query - ImmutableGiven an integer array nums, handle multiple queries of the following type:Calculate the sum of the elements of nums between indices left and right inclusive where left <= right.Implement the NumArray class:NumArra原创 2021-12-14 07:38:45 · 389 阅读 · 0 评论