LeetCode解题记录(贪心算法)(一)】的更多相关文章

1. 前言 由于后面还有很多题型要写,贪心算法目前可能就到此为止了,上一篇博客的地址为 LeetCode解题记录(贪心算法)(一) 下面正式开始我们的刷题之旅 2. 贪心 763. 划分字母区间(中等) 题目链接 思路 想切割,要有首尾两个指针,确定了结尾指针,就能确定下一个切割的开始指针. 遍历字符串,如果已扫描部分的所有字符,都只出现在已扫描的范围内,即可做切割. 注意 : 贪心的思想为,只要是扫描过的字符,都出现在我扫描的范围之类,我就切割,不去考虑其他的条件,这样能保证切割的数量最多 代…
1. 前言 目前得到一本不错的算法书籍,页数不多,挺符合我的需要,于是正好借这个机会来好好的系统的刷一下算法题,一来呢,是可以给部分同学提供解题思路,和一些自己的思考,二来呢,我也可以在需要复习的时候,通过博客来回顾自己,废话不多说,开始! 目前的规划 2. 算法解释 顾名思义,贪心算法或贪心思想采用贪心的策略,保证每次操作都是局部最优的,从而使最后得到的结果是全局最优的. 举一个最简单的例子:小明和小王喜欢吃苹果,小明可以吃五个,小王可以吃三个.已知苹果园里有吃不完的苹果,求小明和小王一共最多…
贪心算法篇 # 题名 刷题 通过率 难度 44 通配符匹配   17.8% 困难 45 跳跃游戏 II   25.5% 困难 55 跳跃游戏   30.6% 中等 122 买卖股票的最佳时机 II C#LeetCode刷题之#122-买卖股票的最佳时机 II(Best Time to Buy and Sell Stock II) 48.8% 简单 134 加油站   40.0% 中等 135 分发糖果   33.0% 困难 316 去除重复字母   21.6% 困难 321 拼接最大数   20…
Jump Game 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 maximum jump length at that position. Determine if you are able to reach the last index. For ex…
尽量抽空刷LeetCode,持续更新 刷题记录在github上面,https://github.com/Zering/LeetCode 2016-09-05 300. Longest Increasing Subsequence 问题:https://leetcode.com/problems/longest-increasing-subsequence/ 分析:http://zering.me/2016/09/02/Longest-Increasing-Subsequence/ 源码:http…
1. 算法解释 双指针主要用于遍历数组,两个指针指向不同的元素,从而协同完成任务.也可以延伸到多个数组的多个指针. 若两个指针指向同一数组,遍历方向相同且不会相交,则也称为滑动窗口(两个指针包围的区域即为当前的窗口),经常用于区间搜索. 若两个指针指向同一数组,但是遍历方向相反,则可以用来进行搜索,待搜索的数组往往是排好序的. 对于 C++ 语言,指针还可以玩出很多新的花样.一些常见的关于指针的操作如下. 1.1 指针与常量 1.2 指针函数与函数指针 static string Blog_Ad…
135. Candy There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get mo…
Best Time to Buy and Sell Stock II 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. You may complete as many transactions as you like (ie, buy one and sell one sha…
先看一道leetcode题: Best Time to Buy and Sell Stock II 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. You may complete as many transactions as you like (ie, buy one a…
贪心算法#结构体 Problem Description "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@#$%^&*%..." 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了. 作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事).非常6+7.超级女…