摘要: 这道题为简单题 题目: 思路: 其实这个题主要是需要注意负数的问题,首先我把列表进行排序,可能有人到这个会有多种考虑,但是实际上返回最大值的情况只有两种,(1)、列表最开始两个元素乘以最后的一个元素;(2)、列表最后面3个元素相乘。根本不用考虑每个元素的正负性。 代码: 阅读全文
posted @ 2017-09-21 16:58 唐僧洗发爱飘柔 阅读(122) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: 思路: 我先把前k个数加起来计算平均值,然后遍历列表从索引(k, len(nums)),每次列表向右移动一次就把最左边的的元素减去再加上最新的这个元素,计算总值再求平均值,并与之前的最大值比较,遍历结束后可得最大值。 代码: 阅读全文
posted @ 2017-09-21 16:56 唐僧洗发爱飘柔 阅读(85) 评论(0) 推荐(0)
摘要: 本人新手,在leetcode刷题过程中出现过很多问题,也发现了很多方法,故在此总结,不定时更新。 1、在创建一个二维列表的时候,我之前会用 a = [[0] * 5] * 5, 但是这样输出的结果往往会跟期待的不一样,我一直以为是我的程序有问题,百度了很久也不知道错误在哪儿,后来看见别人的解法,自己 阅读全文
posted @ 2017-09-21 16:48 唐僧洗发爱飘柔 阅读(159) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: 思路: 遍历每一个元素,并且判断元素所在的九宫格的每个元素是否存在,存在Num计数加1,total加上每个元素,该元素遍历完时,total // num变为新列表a对应位置的值。 代码: 阅读全文
posted @ 2017-09-21 16:16 唐僧洗发爱飘柔 阅读(107) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. Yo 阅读全文
posted @ 2017-09-21 14:36 唐僧洗发爱飘柔 阅读(110) 评论(0) 推荐(0)
摘要: 这是一道我觉得有点不是很好的简单题 题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note: You may assume that nums1 has 阅读全文
posted @ 2017-09-19 17:09 唐僧洗发爱飘柔 阅读(140) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may ass 阅读全文
posted @ 2017-09-19 12:04 唐僧洗发爱飘柔 阅读(97) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given n 阅读全文
posted @ 2017-09-18 23:29 唐僧洗发爱飘柔 阅读(180) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums 阅读全文
posted @ 2017-09-18 20:19 唐僧洗发爱飘柔 阅读(83) 评论(0) 推荐(0)
摘要: 这道题为简单题 题目: Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twic 阅读全文
posted @ 2017-09-18 18:53 唐僧洗发爱飘柔 阅读(91) 评论(0) 推荐(0)