题目:
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.
The array may contain duplicate...
分类:
编程语言 时间:
2015-02-04 16:39:32
阅读次数:
150
题目:与33题类似,也是在被翻转的有序数组中查找元素。不同的是数组中可能有重复的元素出现。
分析:数组中的元素可以重复导致的问题就是如果first小于等于mid,那么前半部分也不一定是有序的,例如[1 3 1 1 1 1 1 ]。因此我们把判断条件进一步细分,分为三种情况,大于,小于和等于。等于的时候直接first++就可以了。
代码:class Solution {
public:
...
分类:
其他好文 时间:
2015-02-04 13:08:15
阅读次数:
148
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.
题目:合并两个单链表
思路:先比较两个各链表第一个节点,大的那个节点先设为合并的链表第一个节点,...
分类:
其他好文 时间:
2015-02-04 13:06:08
阅读次数:
136
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. 题目意思很简单....
分类:
其他好文 时间:
2015-02-04 12:41:16
阅读次数:
132
原文链接:http://www.infoq.com/cn/articles/tq-redis-memory-usage-optimization-storageRedis常见数据模型的使用场景以及在内存优化方面和性能优化方面的分析:常见类型:String、 Hash、 set、 sorted set...
分类:
其他好文 时间:
2015-02-04 10:47:00
阅读次数:
224
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'34: Search for a Rangehttps://oj.leetcode.com/problems/search-for-a-range/Given a sorted a...
分类:
编程语言 时间:
2015-02-04 01:55:27
阅读次数:
207
Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if ...
分类:
其他好文 时间:
2015-02-03 22:42:04
阅读次数:
152
排序分为两种,一种原地排序,一种是复制排序>>>data=[1,4,2,8,9,5,6,0]>>>data.sort()>>>>>>data[0,1,2,4,5,6,8,9]>>>data=[4,66,7,2,7,9,0,5,]>>>data2=sorted(data)>>>>>>data2[0,2...
分类:
编程语言 时间:
2015-02-03 22:37:58
阅读次数:
229
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/Given a sorted array, remove the duplicates in place such that each element appea...
分类:
其他好文 时间:
2015-02-03 22:34:48
阅读次数:
208
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or...
分类:
其他好文 时间:
2015-02-03 20:58:39
阅读次数:
133