Algorithm
彼得.攀
就是想开个博客
展开
-
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 · 520 阅读 · 0 评论 -
Google Kick Start 2019 F轮题解
原文首发自彼得攀的小站查阅更多的题解,请点击github传送门本次的A题比较难,应该算leetcode中的Hard+,类似leetcode 265,但会更难一点:leetcode 265用二维dp即可,而A题需要三维dpA. Flattening题目地址Solution这道题比较难,做的时候感觉DP不易解,用了贪心,3个小时有一个半小时都在调这个,最后还是没调出来…后面看了官方题解...原创 2019-10-04 15:10:47 · 398 阅读 · 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 · 628 阅读 · 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 · 311 阅读 · 0 评论 -
Google Kick Start 2019 C轮 题解
原文出自彼得攀的小站查阅更多的题解,请点击github传送门A.Wiggle WalkBanny has just bought a new programmable robot. Eager to test his coding skills, he has placed the robot in a grid of squares with R rows (numbered 1 to ...原创 2019-09-21 20:22:16 · 723 阅读 · 0 评论 -
Google Kick Start 2018 A轮题解
原文出自彼得攀的小站查阅更多的题解,请点击github传送门A.Even Digits題目地址Solution题目大意題目大意是給定一个数,每次只能加一或是减一,用最少的次数将其变成一个每位数都是偶数的数,求这个次数是多少解法小数据集可以暴力求解,尝试加和减两个方向,直至有一个方向达到要求考虑一个数中存在为奇数的位,显然对结果影响最大的是从高到低第一个奇数,考虑将其变成偶数...原创 2019-09-21 20:20:32 · 316 阅读 · 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 · 239 阅读 · 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 · 117 阅读 · 0 评论 -
LeetCode 140. Word Break II(Hard)
查阅更多的题解,请点击Problem140. Word Break II(Hard)Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a val...原创 2019-06-21 12:26:06 · 122 阅读 · 0 评论 -
LeetCode 139 Word Break(Medium)
查阅更多的题解,请点击Problem139. Word Break(Medium)Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence o...原创 2019-06-21 12:22:46 · 143 阅读 · 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 · 104 阅读 · 0 评论 -
计算复杂性理论
查看原文,点我计算复杂性理论在计算机算法中,计算复杂性是一个很重要的研究内容。计算复杂性理论(Computational complexity theory)被认为是理论计算机科学和数学的一个分支。对于计算机而言,任何一个问题的求解都需要资源(即使是最简单的1+1的问题)。计算复杂性理论通过引入数学计算模型来研究这些问题以及定量计算解决问题所需的资源(时间和空间),从而将资源的确定方法正式化...原创 2019-06-09 00:24:03 · 8208 阅读 · 2 评论 -
算法笔记(一)-概论
本文是算法笔记系列的开端,内容主要参考卜东波老师授课内容、算法导论学习整理及平日的一些积累概述无论是生活还是科研、工作中遇到的问题,通常可以采用下述的过程去解决找到需要解决的实际问题将实际问题形式化为数学形式找到求解问题的算法这里很重要的两部分是:将实际问题形式化为数学形式和设计求解问题的算法。这个系列的笔记主要是关注找到求解问题的算法,下面是一个求解问题的思路树:...原创 2019-06-09 00:19:05 · 278 阅读 · 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 · 118 阅读 · 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 · 119 阅读 · 0 评论 -
LeetCode 380. Insert Delete GetRandom O(1)(Medium)
查阅更多的题解,请点击Problem380. Insert Delete GetRandom O(1)(Medium)Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not a...原创 2019-04-17 21:24:17 · 179 阅读 · 0 评论 -
LeetCode 328. Odd Even Linked List(Medium)
查阅更多的题解,请点击Problem328. Odd Even Linked List(Medium)Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not...原创 2019-04-21 14:12:52 · 152 阅读 · 0 评论 -
LeetCode 42. Trapping Rain Water(Hard)
查看原文,请点击彼得.攀的小站查阅更多的题解,请点击Problem42. Trapping Rain Water(Hard)Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to tra...原创 2019-04-12 09:06:14 · 251 阅读 · 0 评论 -
LeetCode 73. Set Matrix Zeroes(Medium)
原文出处,请点击彼得攀的小站查阅更多的题解,请点击Problem73. Set Matrix Zeroes(Medium)Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in-place.Example 1:Input: [ [1,1,1], [1,...原创 2019-04-10 21:35:11 · 95 阅读 · 0 评论