问题
查找某个值在list中的位置
解决思路
可以用折半查询的方法解决此问题。
解决(Python)
#! /usr/bin/env python
#coding:utf-8
#折半查找某个元素在list中的位置
def half_search(lst,value,left,right):
length = len(lst)
while left<ri...
分类:
其他好文 时间:
2014-06-19 11:09:48
阅读次数:
527
运用.NET Framework类来解析HTML文件、读取数据并不是最容易的。虽然你可以用.NET Framework中的许多类(如StreamReader)来逐行解析文件,但XmlReader提供的API并不是“取出即可用(out of the box)”的,因为HTML的格式不规范。你可以用正则...
分类:
Web程序 时间:
2014-06-15 23:23:58
阅读次数:
712
伸展树是那么的迷人,总是让你在希望的时候WA,在绝望的时候AC。。。。。
做这个题没有之前,首先要了解树形结构转线性的做法。
推荐连接:http://blog.csdn.net/lyhypacm/article/details/6734748
本题做法:
对于本题的每一个最外层的盒子建立一颗伸展树。
对于move x y操作:
(1)把x为根的子树切下来。
(2)然后把切下来的子树放...
分类:
其他好文 时间:
2014-06-15 19:10:47
阅读次数:
302
在看网上别的前端大牛的作品时,总会有新的收获,我想很多人应该都知道box-shadow,但是不知道有没有接触过这个box-shadow: 2px 2px 4px rgba(0,0,0,0.4) ,现在就来介绍下,其中,rgba是CSS3中的属性,rgba括号中前3个数字代表着 red gree...
分类:
Web程序 时间:
2014-06-15 17:42:40
阅读次数:
219
旋转数组中的查找。[1, 2, 3, 4, 5, 6]的一个旋转数组为[4, 5, 6, 1, 2, 3]。在旋转数组中寻找一个数。
最直接的方法,一次遍历,时间复杂度O(n)。但是既然是一个部分有序的数组,那么对于有序的部分我们可以想方法用二分查找。这个效率可以提高。
代码:
.......
分类:
其他好文 时间:
2014-06-15 17:33:21
阅读次数:
195
题目
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 order.
You may assume no duplicates i...
分类:
其他好文 时间:
2014-06-15 17:27:16
阅读次数:
251
题目
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log n).
If the target i...
分类:
其他好文 时间:
2014-06-15 16:53:32
阅读次数:
177
题目
Given a sorted array of integers, find the starting and ending position of a given target value.
解题思路:
查找一个数出现的范围,给一个排好序的数组和一个数,找出这个数在数组中出现的范围。
这个题直接使用一次遍历就可以得到结果,这样的时间复杂度为O(n)。但是对于有序数组我们一般可以使用二分查找可以得到更好的O(logn)的时间复杂度。我们可以使用二分查找找到这个数第一次出现的位置和这个数最后一次出现的位...
分类:
其他好文 时间:
2014-06-15 16:19:16
阅读次数:
237
1、
??
Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.
For example,
Given n = 3, your program should return all 5 uni...
分类:
其他好文 时间:
2014-06-15 09:09:00
阅读次数:
256
首先通过你要下载的歌曲通过下列连接:
http://box.zhangmen.baidu.com/x?op=12&count=1&title={title}$${author}$$$$
可以获取一个xml文件通过解析xml文件就可以读取到音乐下载的地址和歌词下载的地址。
部分代码:
String title = "六月的雨";
String singer = "胡歌"; ...
分类:
移动开发 时间:
2014-06-14 07:01:42
阅读次数:
334