![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++11
彼得.攀
就是想开个博客
展开
-
Google Kick Start 2019 G轮题解
首发于彼得攀的小站查阅更多的题解,请点击github传送门 (求个star哇)A. Book Reading题目地址Solution解法本题如果采用暴力求解,最坏情况下,每个读者都需要O(n)O(n)O(n) time, 则总的时间复杂度为O(nq)O(nq)O(nq) time. (一个简单的例子,q个读者对应的RiR_iRi都是1,那么每个读者都要算n次)为了避免上述暴力过程...原创 2019-10-21 20:39:24 · 492 阅读 · 0 评论 -
LeetCode 1218. Longest Arithmetic Subsequence of Given Difference 题解
查阅更多的题解,请点击GitHub传送门Problem1218. Longest Arithmetic Subsequence of Given DifferenceSolutionDP, O(n) time題目是求最长的等差序列,利用dp求解,假设前i个数我们已经得到解,那么加入第i+1个数x,若x-difference在前i个数中存在,那么更新之前候选序列;若不存在,x可以作为一个...原创 2019-10-08 20:19:44 · 327 阅读 · 0 评论 -
Google Kick Start 2019 E轮题解
原文出自彼得攀的小站查阅更多的题解,请点击github传送门A. Cherries Mesh题目地址Solution解法这个点心本身就构成了一个完全图,其中的边权值为1或者2,去掉一些边使得甜度最小,并且仍然连通,问题就相当于求一个带权完全图的最小生成树的权值,那么可以采用prim算法,这里是O(n^2) time. 这样的解法可以通过test 1.注意题目的特殊性:边的权值要么为...原创 2019-09-21 20:30:17 · 619 阅读 · 0 评论 -
Google Kick Start 2019 D轮题解
原文出自彼得攀的小站查阅更多的题解,请点击github传送门A. X or What?题目地址Solution解法解题关键在于异或的性质,将数都看作二进制表示,同一位上1和1异或得0, 0和1异或得0, 0和0异或得1:两数异或,若两个数的二进制表示均有偶数个1,那么异或结果也一定有偶数个1 => 1的个数以2的倍数增减两数异或,若一个数二进制表示有偶数个1,另一个有奇...原创 2019-09-21 20:29:12 · 303 阅读 · 0 评论 -
LeetCode 395. Longest Substring with At Least K Repeating Characters(Medium)题解
查阅更多的题解,请点击Problem395. Longest Substring with At Least K Repeating Characters(Medium)Find the length of the longest substring T of a given string (consists of lowercase letters only) such that ever...原创 2019-06-30 13:48:12 · 212 阅读 · 0 评论 -
LeetCode 41. First Missing Positive(Hard)
查阅更多的题解,请点击Problem41. First Missing Positive(Hard)Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Outp...原创 2019-06-26 14:29:41 · 105 阅读 · 0 评论 -
LeetCode 300. Longest Increasing Subsequence(Medium)
查阅更多的题解,请点击Problem300. Longest Increasing Subsequence(Medium)Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 ...原创 2019-06-10 19:02:59 · 100 阅读 · 0 评论 -
算法笔记(一)-概论
本文是算法笔记系列的开端,内容主要参考卜东波老师授课内容、算法导论学习整理及平日的一些积累概述无论是生活还是科研、工作中遇到的问题,通常可以采用下述的过程去解决找到需要解决的实际问题将实际问题形式化为数学形式找到求解问题的算法这里很重要的两部分是:将实际问题形式化为数学形式和设计求解问题的算法。这个系列的笔记主要是关注找到求解问题的算法,下面是一个求解问题的思路树:...原创 2019-06-09 00:19:05 · 262 阅读 · 0 评论 -
LeetCode 45. Jump Game II(Hard)
查阅更多的题解,请点击Problem45. Jump Game II(Hard)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...原创 2019-06-09 00:16:53 · 113 阅读 · 0 评论 -
LeetCode 84. Largest Rectangle in Histogram(hard)
查阅更多的题解,请点击SolutionStack O(n) time, O(n) spacenote: 用s[k]代表第k+1个元素首先观察问题,不能直接得到一个很好的reduce原问题的策略。确定一个矩形有三要素:左边界、右边界和高(即左右边界及中间部分值最小的元素,称为bar)。“没有smart”的策略,那么按照最朴素的想法求解:选择一个元素作为可能最大矩阵的bar,向左右扩展寻找左...原创 2019-06-09 00:15:09 · 113 阅读 · 0 评论