![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
herosunly
985院校硕士毕业,现担任算法研究员一职,热衷于大模型算法的研究与应用。曾担任百度千帆大模型比赛、BPAA算法大赛评委,编写微软OpenAI考试认证指导手册。曾获得多项AI顶级比赛的Top名次,其中包括阿里云天池安全恶意程序检测第一名,科大讯飞恶意软件分类挑战赛第三名,CCF恶意软件家族分类第四名,科大讯飞阿尔茨海默综合症预测挑战赛第四名,科大讯飞事件抽取挑战赛第七名,Datacon大数据安全分析比赛第五名。授权多项发明专利。对机器学习和深度学习拥有自己独到的见解。曾经辅导过若干个非计算机专业的学生进入到算法行业就业。希望和大家一起成长进步。
展开
-
使用区间来简化代码思考
Leetcode中移动零(https://leetcode-cn.com/problems/move-zeroes/)和快速排序的最初版本,本质上都可以使用区间来简化代码。 首先以移动零为例,假设两个循环变量分别为jjj和iii(假设j<=ij<=ij<=i),则[0,...,j][0,...,j][0,...,j]中均为非零元素(区间1),而[j+1,...,i−1][j+1,...,i-1][j+1,...,i−1]均为零(区间2)。其中i是从最开始滑到最后一个元素的。原创 2020-07-06 16:40:34 · 8192 阅读 · 2 评论 -
Leetcode最大和最小子序和
class Solution: def maxSubArray(self, nums: List[int]) -> int: if len(nums) == 0: return 0 global_max = nums[0] step_max = nums[0] if len(nums) == 1: return global_max for i in range原创 2020-06-09 14:53:37 · 8947 阅读 · 8 评论 -
代码思路标准流程
首先引入几个基本概念。fff代表指定的函数。每一步(step)和每一轮(round)。假设为二重循环,则外层循环一次代表走一轮,而内层循环一次代表走一步。如果是一重循环,则循环一次代表走一步。 以冒泡排序为例,假设冒泡排序为函数fff,则表达式即为f(x1,x2,…,xn)f(x_1,x_2,\dots,x_n)f(x1,x2,…,xn)。为了更好的理解复杂的情况,我们先理解最简单的情形:假设只包括单个元素时:f(x1)=x1f(x_1)=x_1f(x1)=x1假设元素个数为2个时:原创 2020-06-09 10:17:12 · 8958 阅读 · 3 评论 -
Leetcode学习
1. 刷题方法 自顶向下 VS 自底向上。两种方法各有优劣。那怎么才能达到最好的学习效果呢? 入门时使用自底向上的学习方法,以玩游戏为例,了解了基本的游戏规则,然后就先玩起来,在玩的过程中逐渐熟悉。但这样的玩法,必然会在一定阶段遇到瓶颈,问题的本质在哪里,那如何解决呢? 深入时再对对应的章节采用自顶向下的学习方法。比如通过阅读算法的参考书籍,如图解算法、算法(第4版)。1.1 第一遍(第一次梳理思路,可依赖) 自己独立思考,理解题意,明确边界条件。基础薄弱(刷题少于100道)的同学,思考时原创 2020-06-01 16:47:09 · 10385 阅读 · 6 评论 -
Leetcode 24 Swap Nodes in Pairs
1.开篇X:DataX:DataX:Dataθ:Parameter\theta:Parameterθ:ParameterX=(x1x2...xN)T=X = (x_1\quad x_2 \quad... \quad x_N)^T = X=(x1x2...xN)T=(x11x12...x1px21x22...x2p............xN1xN2...xNp)N×p\begin...原创 2020-03-04 20:20:59 · 2901 阅读 · 0 评论 -
Leetcode 86 Partition List
题意描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each ...原创 2019-02-25 12:51:28 · 12631 阅读 · 0 评论 -
Leetcode 83 Remove Duplicates from Sorted List
题意描述Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2思路解析该题只需要两个指针,prev和cur即可。为什么不需要nex呢?这个问题值得思考。是因为在之前的问...原创 2019-02-17 17:11:12 · 10988 阅读 · 0 评论 -
Leetcode 92 Reverse Linked List II
题意描述Reverse a linked list from position m to n. Do it in one-pass.Note: 1 ≤ m ≤ n ≤ length of list.Example:Input: 1->2->3->4->5->NULL, m = 2, n = 4Output: 1->4->3->2->5...原创 2019-02-17 11:53:53 · 10357 阅读 · 4 评论 -
Leetcode 206 Reverse Linked List
题意描述Reverse a singly linked list.反转链表是一个基础问题,但也是一个很重要的问题。Example:Input: 1-&gt;2-&gt;3-&gt;4-&gt;5-&gt;NULLOutput: 5-&gt;4-&gt;3-&gt;2-&gt;1-&gt;NULL思路解析一通过prev、cur、nex三个指原创 2019-02-17 11:32:57 · 13135 阅读 · 0 评论 -
Leetcode 80 Remove Duplicates from Sorted Array II
题目描述Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twice and return the new length.Do not allocate extra space for another array, you must do this by...原创 2019-01-28 19:21:13 · 12610 阅读 · 0 评论 -
Leetcode 26 Remove Duplicates
Leetcode 26 Remove Duplicates题目描述Remove Duplicates from Sorted ArrayGiven a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not al...原创 2019-01-25 19:48:03 · 10403 阅读 · 0 评论 -
Leetcode 75 Sort Colors
Leetcode 75 Sort ColorsGiven an array with n objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.H...原创 2019-01-25 19:25:29 · 10328 阅读 · 0 评论 -
Leetcode 27 Remove Element
题目描述给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度。不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成。元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。Example 1:Given nums = [3,2,2,3], val = 3,Your function shou...原创 2019-01-25 01:07:56 · 10300 阅读 · 2 评论 -
Leetcode 283 Move Zeroes
题目描述给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序。示例:输入: [0,1,0,3,12]输出: [1,3,12,0,0]说明:必须在原数组上操作,不能拷贝额外的数组。尽量减少操作次数思路分析之基本套路在不申请新的数组的前提下,遍历一遍数组,而且只使用一个索引变量,是无法求解这个题目。既然无法使用一个索引变量,那我们是否能使用...原创 2019-01-25 00:30:40 · 10709 阅读 · 8 评论