![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
双指针
aaaqqq1234
这个作者很懒,什么都没留下…
展开
-
排序数组中删除重复元素
题目intput=【1,1,2】output = 【1,2,X】思路双指针代码def removeDuplicates(list1): tail = 0 for i in range(1,len(list1)): if list1[tail] != list1[i]: tail += 1 list1[tail] = list1[i] tail = tail +1 while tail<len(l原创 2020-08-04 22:06:21 · 88 阅读 · 0 评论 -
连续子串的最大值
题目给定一个数组,求这个最大连续子串不超过k的最大值。思路两个循环,if 条件判定def maxSubArray(nums,target): max1 = float('-inf') list1 = [] for i in range(len(nums)): local = 0 for j in range(i, len(nums)): local += nums[j] if local<t原创 2020-08-04 20:13:45 · 202 阅读 · 0 评论 -
最大矩形面积
题目输入: [2,1,5,6,2,3]输出: 10思路单调栈代码def largestRectangleArea(heights): max_ans = 0 heights = [0]+heights +[0] length = len(heights) stack = [0] for i in range(1,length): while heights[i]<heights[stack[-1]]: h =原创 2020-08-04 19:28:17 · 102 阅读 · 0 评论 -
2-4数之和
题目2,3,4数之和非leetcode,自己酌情修改亲测可过思路双指针加循环代码def twosum(num,target): #dict dict = {} for i,nums in enumerate(num): if nums in dict: return [dict[nums],i] else: dict[target - nums]=ia = twosum([1,2,4,6,7,9]原创 2020-08-03 16:07:35 · 124 阅读 · 0 评论