随笔分类 -  算法题目全解

摘要:Array题目总结 1.题目分类 双指针 同向双指针 相向双指针 滑动窗口 使用hash map进行count 前缀和、后缀和 利用前缀和降低时间复杂度 前缀和 + Hash Table : 这类题目其实都是2Sum的变种,利用hash table记录下标,从而如果发现有合法的子数组后,能够直接 阅读全文
posted @ 2019-01-26 13:35 shawshawwan 阅读(371) 评论(0) 推荐(0)
摘要:"943.Find the Shortest Superstring" Given an array A of strings, find any smallest string that contains each string in A as a substring. We may assume 阅读全文
posted @ 2019-01-19 15:32 shawshawwan 阅读(1090) 评论(0) 推荐(0)
摘要:今天算法群里出的一道题,题目不难,但是这道题有多种解法,而且注意分析每种解法的时间复杂度,不能超时 题目: We have jobs: difficulty[i] is the difficulty of the ith job, and profit[i] is the profit of the 阅读全文
posted @ 2019-01-16 11:07 shawshawwan 阅读(349) 评论(0) 推荐(0)
摘要:今天做周赛又碰到了单调栈的题目,之前没有做好总结,这次好好总结下 1.基本思想 单调栈求解的基本问题 在一个线性数据结构中,为任意一个元素找左边和右边第一个比自己大/小的位置,要求O(n)的复杂度 基本解法很容易想到O(n^2)的解法,关键是O(n)的解法,就需要借助单调栈了。单调栈的一大优势就是线 阅读全文
posted @ 2018-12-23 23:29 shawshawwan 阅读(1404) 评论(0) 推荐(0)
摘要:146. LRU Cache 数据结构神题 题意 实现一个LRU Cache 思路 hash table + 双向链表 链表头存着最近的节点,链表尾存着最近最少使用的节点 代码 这版应该是写的最简洁的一版了,就是有很多条件需要考虑清楚 这题应该多练几遍,面试时30分钟能写出 阅读全文
posted @ 2018-12-14 14:38 shawshawwan 阅读(209) 评论(0) 推荐(0)
摘要:好久没写题解了,今天做了一道图题,觉得解法很不错。 题目: Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itine 阅读全文
posted @ 2018-11-01 12:01 shawshawwan 阅读(321) 评论(0) 推荐(0)
摘要:本系列为《挑战程序设计竞赛》读书笔记,分为初级篇、中级篇、高级篇 阅读全文
posted @ 2018-08-30 10:00 shawshawwan 阅读(359) 评论(0) 推荐(0)
摘要:本系列为《挑战程序设计竞赛》读书笔记,分为初级篇、中级篇、高级篇 本系列为《挑战程序设计竞赛》读书笔记,分为初级篇、中级篇、高级篇 阅读全文
posted @ 2018-08-30 09:59 shawshawwan 阅读(291) 评论(0) 推荐(0)
摘要:本系列为《挑战程序设计竞赛》读书笔记,分为初级篇、中级篇、高级篇 初级篇目录: 1.穷竭搜索 a.核心思想: DFS :从某个状态开始,不断转移,直至无法转移,回退到前一步,再继续转移到其他状态,直到找到最终解;一般使用递归或者栈实现 BFS 从初始状态开始,总是先搜索至距离初始状态近的状态。每个状 阅读全文
posted @ 2018-08-30 09:58 shawshawwan 阅读(817) 评论(0) 推荐(0)
摘要:题意:Given an array of unique integers, each integer is strictly greater than 1. We make a binary tree using these integers and each number may be used 阅读全文
posted @ 2018-08-30 09:44 shawshawwan 阅读(382) 评论(0) 推荐(0)
摘要:【转自一亩三分田】谈谈面试官在面试coding题目时的考察终点与心理活动 本人简介: 曾经微软dev, 35+, 10年经验, 有FLG offer. 去年加入一个start up 公司, 最近前景不明, 在犹豫要不要去个稳定点的大公司。 我从sde开始面试其他人, 到现在估计面试过100+人次的面 阅读全文
posted @ 2018-08-18 22:16 shawshawwan 阅读(911) 评论(0) 推荐(0)
摘要:好久没刷题了,今天碰巧看见一道很有趣的题,给大家分享分享: https://leetcode.com/problems/rabbits-in-forest/description/ In a forest, each rabbit has some color. Some subset of rab 阅读全文
posted @ 2018-07-26 21:46 shawshawwan 阅读(362) 评论(0) 推荐(0)
摘要:Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, 阅读全文
posted @ 2018-06-24 17:22 shawshawwan 阅读(217) 评论(0) 推荐(0)
摘要:数组 1.如果题目要求O(n)复杂度,一般就需要考虑使用two pointer 或者sliding window或者HashMap、 HashSet eg: https://leetcode.com/problems/longest-consecutive-sequence/description/ 阅读全文
posted @ 2017-11-28 15:39 shawshawwan 阅读(468) 评论(0) 推荐(0)
摘要:本笔记主要记录在刷九章题目中的思路、问题,以及不能bug-free的原因。 Time Complexity in Coding Interview • O(1) 极少 • O(logn) 几乎都是二分法 • O(√n) 几乎是分解质因数 • O(n) 高频 • O(nlogn) 一般都可能要排序 • 阅读全文
posted @ 2017-10-03 11:53 shawshawwan 阅读(6086) 评论(0) 推荐(0)