05 2019 档案
摘要:Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both?
阅读全文
摘要:Given a singly linked list, determine if it is a palindrome. Example 1: Example 2: Follow up:Could you do it in O(n) time and O(1) space? (1)定义快慢指针得到链
阅读全文
摘要:Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacen
阅读全文
摘要:Given a non-empty array of integers, return the k most frequent elements. Example 1: Example 2: Input: nums = [1], k = 1 Output: [1] 这个题目更加像是一道语法题目。。。
阅读全文
摘要:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]). Y
阅读全文
摘要:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 样例: 首先有两种思路: 二分查找是最直观的,横的方向和竖方向都是有序数列。所以可以遍历横方向然后利用二分查找。O(nlogn)
阅读全文
摘要:请实现一个函数,把字符串中的每个空格替换成"%20"。 你可以假定输入字符串的长度最大是1000。注意输出字符串的长度可能大于1000。 样例 (双指针扫描) O(n)在部分编程语言中,我们可以动态地将原数组长度扩大,此时我们就可以使用双指针算法,来降低空间的使用: 首先遍历一遍原数组,求出最终答案
阅读全文
摘要:剑指offer 写所有的题解 Redis 书 开课吧 模板题 书 开课吧
阅读全文
摘要:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the
阅读全文
摘要:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数。 例如输入12,从1到12这些整数中包含“1”的数字有1,10,11和12,其中“1”一共出现了5次。 输入: 12 输出: 5 从1到n,每增加1,weight就会加1,当weight加到9时,再加1又会回到0重新开始。那么weigh
阅读全文
摘要:二分模板一共有两个,分别适用于不同情况。算法思路:假设目标值在闭区间[l, r]中, 每次将区间长度缩小一半,当l = r时,我们就找到了目标值。 版本1 在单调递增序列a中查找>=x的数中最小的一个(即x或x的后继)low_bound 当我们将区间[l, r]划分成[l, mid]和[mid +
阅读全文