算法-贪心
sparksnail
这个作者很懒,什么都没留下…
展开
-
LeetCode 134. Gas Station
题目There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to ...原创 2018-04-02 08:37:55 · 147 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II
题目代码class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ count = 0 for i in range(1, len(prices)): ...原创 2018-07-10 02:21:41 · 191 阅读 · 0 评论 -
LeetCode 665. Non-decreasing Array
题目代码class Solution: def checkPossibility(self, nums): """ :type nums: List[int] :rtype: bool """ count = 0 for i in range(len(nums)): ...原创 2018-07-10 02:20:35 · 236 阅读 · 0 评论 -
LeetCode 392. Is Subsequence
题目代码class Solution: def isSubsequence(self, s, t): """ :type s: str :type t: str :rtype: bool """ i = 0; j = 0 index = 0 f...原创 2018-07-10 02:19:32 · 198 阅读 · 0 评论 -
LeetCode 605. Can Place Flowers
题目代码class Solution: def canPlaceFlowers(self, flowerbed, n): """ :type flowerbed: List[int] :type n: int :rtype: bool """ length = len(flo...原创 2018-07-10 02:18:29 · 192 阅读 · 0 评论 -
LeetCode 763. Partition Labels
题目代码class Solution: def partitionLabels(self, S): """ :type S: str :rtype: List[int] """ tmp_dict = {c:i for i, c in enumerate(S)} res_lis...原创 2018-07-10 02:17:24 · 196 阅读 · 0 评论 -
LeetCode 406. Queue Reconstruction by Height
题目代码class Solution: def insert(self, people, fromindex, toindex): tmp = people[fromindex] for i in range(toindex + 1, fromindex + 1)[::-1]: people[i] = people...原创 2018-07-10 02:16:15 · 186 阅读 · 0 评论 -
LeetCode 452. Minimum Number of Arrows to Burst Balloons
题目代码class Solution: def findMinArrowShots(self, points): """ :type points: List[List[int]] :rtype: int """ count = 0 i = 0; j = 0 end ...原创 2018-07-10 02:14:47 · 190 阅读 · 0 评论 -
LeetCode 435. Non-overlapping Intervals
题目思路贪心代码# Definition for an interval.# class Interval:# def __init__(self, s=0, e=0):# self.start = s# self.end = eclass Solution: def eraseOverlapIntervals(s...原创 2018-07-10 02:12:04 · 219 阅读 · 0 评论 -
LeetCode 455. Assign Cookies
题目思路贪心代码class Solution: def findContentChildren(self, g, s): """ :type g: List[int] :type s: List[int] :rtype: int """ g.sort() ...原创 2018-07-10 02:09:10 · 294 阅读 · 0 评论 -
LeetCode 122. Best Time to Buy and Sell Stock II
题目思路只要能买股票,变累加进入利润和。代码class Solution: def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ maxProfit = 0 for i i...原创 2018-04-06 01:01:21 · 109 阅读 · 0 评论 -
LeetCode 167. Two Sum II - Input array is sorted
题目代码class Solution: def twoSum(self, numbers, target): """ :type numbers: List[int] :type target: int :rtype: List[int] """ left = 0; righ...原创 2018-07-10 02:22:44 · 252 阅读 · 0 评论