Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
分类:
其他好文 时间:
2014-11-01 11:20:33
阅读次数:
210
今天做了两题,第二题没解出来,发现太麻烦了,放弃了……明天脑子清楚的时候再做。第一题就是标题中的这个问题。在一个旋转排序数组中找出最小的值。针对该问题出了两道不同要求的题目,分别是不考虑重复元素的情况和考虑有重复元素的情况。我的解题思路是,将数组的第一个值存到变量中,循环数组剩余的值,进行比较,第一...
分类:
其他好文 时间:
2014-10-31 22:03:20
阅读次数:
148
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...
分类:
其他好文 时间:
2014-10-31 12:04:22
阅读次数:
223
题目描述:
Suppose a sorted array 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).
Find the minimum element.
You may assume no duplicate...
分类:
其他好文 时间:
2014-10-31 11:57:17
阅读次数:
201
题目描述:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
思路:采用类似折半查找的方式找到当前根节点,则当前根节点左边的属于它的左子树部分,当前根节点右边的属于它的右子树部分。再采用同样的方法,递归地对当前根节点的左右子树做相同的处理。
...
分类:
其他好文 时间:
2014-10-30 19:22:04
阅读次数:
197
题目描述:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
代码:ListNode * Solution::mergeTwoLists(List...
分类:
其他好文 时间:
2014-10-30 11:44:34
阅读次数:
149
Convert Sorted List to Binary Search TreeGiven a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST....
分类:
其他好文 时间:
2014-10-30 10:55:20
阅读次数:
151
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).Find the minimum element.Yo...
分类:
其他好文 时间:
2014-10-30 07:05:17
阅读次数:
260
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time
complexity should be O(log (m+n)).
题意:寻找两个有序数组的中位数,要求复杂度为O(log
(m+...
分类:
其他好文 时间:
2014-10-29 22:23:33
阅读次数:
226
这是letcode上的一道题目 Leetcode: Find Minimum in Rotated Sorted Array
一、什么是旋转数组呢,就是一个有序的数组,在从某一个位置开始,旋转到数组的另一端,例如:0 1 2 3 4 5 6 -> 4 5 6 0 1 2 3
二、使用暴力的方式就是遍历这个数组,算法的复杂度就是O(N),但是根据一般的经验提到有序,就会考虑到使用二分将算法的复杂度降低到O(logn),当然这个题目也不例外,但是如何利用二分去求解呢,毕竟不是全部有序。...
分类:
编程语言 时间:
2014-10-29 19:25:58
阅读次数:
200