/*【程序9】
题目:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3.编程找出1000以内的所有完数。*/
packagetest;
importjava.util.ArrayList;
importjava.util.List;
publicclasstest{
publicstaticbooleanovernum(intnumber){
List<Integer>list=..
分类:
编程语言 时间:
2014-05-27 03:34:38
阅读次数:
245
1、
??
Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
分析:将一个升序排列的链表转换为平衡二叉搜索树,采用递归的方式,先找到链表...
分类:
其他好文 时间:
2014-05-22 12:33:30
阅读次数:
270
【题目】
原文:
2.1 Write code to remove duplicates from an unsorted linked list.
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?
译文:
从一个未排序的链表中移除重复的项
...
分类:
其他好文 时间:
2014-05-22 12:04:13
阅读次数:
196
简介
List是一种可在常数时间内在任何位置执行插入和删除操作的顺序容器。list是双向链表,其迭代器是双向的。与其他顺序容器(array, vector, deque)相比,list容器在任意位置执行插入、提取、和移动元素的操作更高效,但它不能通过在容器中的位置直接获取元素。
成员函数
复制控制
list::list()
...
分类:
编程语言 时间:
2014-05-22 11:44:49
阅读次数:
433
问题描述
对一个单链表进行插入排序,head指向第一个结点。
代码
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/...
分类:
其他好文 时间:
2014-05-22 10:15:43
阅读次数:
233
【题目】
原文:
2.2 Implement an algorithm to find the nth to last element of a singly linked list.
译文:
实现一个算法从一个单链表中返回倒数第n个元素。
【分析】
【思路一】
(1)创建两个指针p1和p2,指向单链表的开始节点。
(2)使p2移动n-1个位置,使之指向从头...
分类:
其他好文 时间:
2014-05-22 09:03:53
阅读次数:
315
问题
Given a singly linked list L: L0→L1→…→Ln-1→Ln,
reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…
You must do this in-place without altering the nodes' values.
For example,
Given {1,2,3,4}, reorde...
分类:
其他好文 时间:
2014-05-22 07:04:46
阅读次数:
298
1. 列表
(1) 建立列表
list(‘python’)
['p', 'y', 't', 'h', 'o', 'n']
(2)列表的常用方法:
append 在列表末尾添加元素
>>>l=[‘a’,’b’,’c’]
>>>l.append(‘d’)
>>>l
['a','b','c','d']
count 统计某个元素在列表中出现的次数
>>>['a','a'...
分类:
编程语言 时间:
2014-05-20 17:00:52
阅读次数:
465
5道题目分别是:【Combinations】、【Search a 2D Matrix】、【Scramble String 】、【Rotate List 】、【Partition List】,由于有一些题目不需要发一整篇博文来记录,所以就将这些题目以一篇博文5道来记录。...
分类:
其他好文 时间:
2014-05-20 15:36:16
阅读次数:
293