
剑指offer
文章平均质量分 82
Yadoer
这个作者很懒,什么都没留下…
展开
-
Search a 2D Matrix(在二维数组中查找)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each原创 2015-03-22 18:58:50 · 1308 阅读 · 0 评论 -
LeetCode-Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha原创 2015-08-25 15:59:19 · 1205 阅读 · 0 评论 -
LeetCode-Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-08-13 15:29:44 · 891 阅读 · 0 评论 -
LeetCode-Implement Queue using Stacks
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empt原创 2015-08-13 20:08:16 · 1065 阅读 · 0 评论 -
LeetCode-Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.此题是Majority Element的继续,关于此题可以移步至Majority Elem原创 2015-08-06 11:03:29 · 1259 阅读 · 0 评论 -
剑指offer-二叉搜索树与双向链表
输入一颗二叉搜索树,将该二叉搜索树转换成一个排序的双向两步。空间复杂度为O(1).最笨的方法就是中序遍历放在一个数组或链表中,再次遍历串联起来。但是要求空间复杂度为O(1),就没办法这么做了,这时候可以参考这个解法。http://blog.youkuaiyun.com/my_jobs/article/details/47666909判断一个树是不是一颗二叉搜索树,可以模仿最后的那个方法。本题跟原创 2015-08-17 15:10:36 · 1332 阅读 · 0 评论 -
LeetCode-Majority Element
题目:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority原创 2015-01-27 10:31:47 · 887 阅读 · 0 评论