介绍了 JDK7 中引入的新的排序算法 TimSort,它来自 Python 中 list 的排序算法。将归并排序(merge sort) 与插入排序(insertion sort) 结合,并进行了一些优化。对于已经部分排序的数组,时间复杂度远低于 O(n log(n)),最好可达 O(n),对于随机排序的数组,时间复杂度为 O(nlog(n)),平均时间复杂度 O(nlog(n))。...
分类:
其他好文 时间:
2014-06-19 12:33:58
阅读次数:
575
该篇文章是一个ListFragment的一个实例,通过了解该实例,更能了解比较常用的ListFragment的用法,以及各Fragment之间的数据传递。
实现效果图:
该MainActivity中包括1个Button+2个Fragment(右边两个),点击Button,出现中间的list列表,点击列表中的任一项,相应item数值,会传递到右边的Fragment中并显示。
源代码:
...
分类:
移动开发 时间:
2014-06-19 11:33:21
阅读次数:
274
问题
查找某个值在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
题目
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
方法
题目中是找出所有的字符串由相同的字符组成,只是顺序不同。
public List anagrams(St...
分类:
其他好文 时间:
2014-06-19 10:46:45
阅读次数:
207
问题
删除一个字符串中连续超过一次的空格。
解决(Python)
#! /usr/bin/env python
#coding:utf-8
def del_space(string):
split_string = string.split(" ") #以空格为分割,生成list,list中如果含有空格,则该空格是连续空格中的后一个
string_list =...
分类:
其他好文 时间:
2014-06-16 11:21:52
阅读次数:
204
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
思路:原有数组需要多出一位的唯一条件是数组所...
分类:
其他好文 时间:
2014-06-15 18:42:43
阅读次数:
162
package com.mylucene;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;...
分类:
其他好文 时间:
2014-06-15 17:50:57
阅读次数:
253
Given a binary tree, flatten it to a linked
list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
分类:
其他好文 时间:
2014-06-13 15:11:35
阅读次数:
273