随笔分类 -  Greedy

贪心算法
[Leetcode 452] 最少需要射出多少支箭Minimum Number of Arrows to Burst Balloons 贪心 重载
摘要:【题目】 There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of th 阅读全文
posted @ 2018-11-28 14:15 alau 阅读(142) 评论(0) 推荐(0)
[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 阅读全文
posted @ 2018-11-19 15:46 alau 阅读(261) 评论(0) 推荐(0)
[Leetcode 392]判断子序列 Is Subsequence
摘要:【思路】 判断s是否为t的子串,所以length(s)<=length(t)。于是两个指针,一次循环。 将s、t转换为数组p1、p2。 i为过程中s的匹配长度。 i=0空串,单独讨论返回true。 当i=p1.length-1时返回true,否则循环结束返回false。 【代码】 【举例】 阅读全文
posted @ 2018-11-09 16:48 alau 阅读(128) 评论(0) 推荐(0)
[Leetcode 376]摇摆序列 Wiggle Subsequence
摘要:【题目】 A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. 阅读全文
posted @ 2018-11-09 16:31 alau 阅读(127) 评论(0) 推荐(0)
[Leetcode 881]船救人 Boats to Save People 贪心
摘要:【题目】 The i-th person has weight people[i], and each boat can carry a maximum weight of limit. Each boat carries at most 2 people at the same time, pro 阅读全文
posted @ 2018-11-07 20:02 alau 阅读(414) 评论(0) 推荐(0)
[Leetcode 55]跳格子JumpGame
摘要:【题目】 Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your 阅读全文
posted @ 2018-10-27 10:36 alau 阅读(438) 评论(0) 推荐(0)