- 博客(7)
- 收藏
- 关注
原创 Leetcode-26-Remove Duplicates from Sorted Array-python
1.1 题目给定一个有序数组,删除重复内容,使每个元素只出现一次,并返回新的长度。不要为其他数组分配额外的空间,您必须通过在 O(1)额外的内存中就地修改输入数组来实现这一点。给定nums = [1,1,2],你的函数应该返回length = 2,前两个nums元素分别是1和2。无论你离开新的长度,都没有关系。1.2 分析及代码这道题的思路,就是利用一个指针遍历数组,将指针此时的数...
2019-04-06 19:18:31
109
原创 Leetcode-18-4Sum-python
1.1 题目给定一个包含 n 个整数的数组 nums 和一个目标值 target,判断 nums 中是否存在四个元素 a,b,c 和 d ,使得 a + b + c + d 的值与 target 相等?找出所有满足条件且不重复的四元组。注意:答案中不可以包含重复的四元组。示例: 给定数组 nums = [1, 0, -1, 0, -2, 2],和 target = 0。 满足要求的四元组...
2019-04-05 20:23:16
136
原创 Leetcode-16-3Sum Closest-python
1.1 题目给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。例如,给定数组 nums = [-1,2,1,-4], 和 target = 1.与 target 最接近的三个数的和为 2. (-1 + 2 + 1 = 2).1.2 分析看完题目,便想...
2019-04-04 16:03:29
129
原创 Leetcode-15-3Sum-python
1.1 题目给定一个整数数组,返回两个数字的索引,使它们加起来一个特定的target.假设每个输入都只有一个解决方案。注意:The solution set must not contain duplicate triplets.Example:Given array nums = [-1, 0, 1, 2, -1, -4],A solution set is:[[-1, 0, 1]...
2019-04-03 16:20:36
276
原创 Leetcode-11-Container With Most Water-python
1.1 题目描述1.2 分析直接利用两重循环,暴力搜索出最大的体积,然后进行输出,进行了提交了,时间超时。然后在阅读答案和其他人员的代码之后,其实比暴力搜索更容易的方式,设立两个指针,一个从头一个从尾,相向而行遍历数组,每次舍弃较短边。(1)暴力搜索class Solution(object): def maxArea(self, height): """ ...
2019-04-02 20:22:25
196
原创 Leetcode-04-Median of Two Sorted Arrays-python
1.1 题目There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).You may assume nums1 ...
2019-04-01 21:40:47
259
2
原创 Leetcode-01-Two Sum-python
1.1 关键字:哈希题目如下:给定一个整数数组,返回两个数字的索引,使它们相加到特定目标。您可以假设每个输入只有一个解决方案,并且您可能不会两次使用相同的元素。Example:Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].分析:最粗暴的方式...
2019-03-31 19:08:08
182
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人