leetcode(数组)
geeker_aaron
这个作者很懒,什么都没留下…
展开
-
8.移动零(Python)
注意理解remove和del的区别!!!参考代码class Solution: def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. ...原创 2018-10-11 11:50:11 · 244 阅读 · 0 评论 -
1.删除排序书中的重复项(Python)
class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i = 0 whi原创 2018-10-09 15:08:55 · 115 阅读 · 0 评论 -
2.买卖股票的最佳时机 II
参考代码class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if prices == None or len(prices) < 2: return 0...原创 2018-10-09 16:33:26 · 120 阅读 · 0 评论 -
3.旋转数组(Python)
思路利用数组切片的思想参考代码class Solution: def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place inste...原创 2018-10-09 17:01:01 · 237 阅读 · 0 评论 -
4.存在重复(Python)
方法一:思路利用count()计数方法来判断参考代码class Solution: def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ for i in nums: if n...原创 2018-10-09 19:49:00 · 890 阅读 · 0 评论 -
5. 只出现一次的数字(Python)
自己的版本:class Solution: def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ for i in nums: if nums.count(i)==1: ...原创 2018-10-09 20:37:16 · 447 阅读 · 0 评论 -
6.两个数组的交集 II(Python)
参考代码class Solution: def intersect(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: List[int] """ res = [] for...原创 2018-10-10 17:14:16 · 188 阅读 · 0 评论 -
7.加一(Python)
思路先把得到的数字结果转化为字符串,在通过过遍历字符串加到数组中参考代码class Solution: def plusOne(self, digits): &quot;&quot;&quot; :type digits: List[int] :rtype: List[int] &quot;&quot;&quot; n原创 2018-10-10 23:01:41 · 266 阅读 · 0 评论