2014年4月2日

【LeetCode练习题】Copy List with Random Pointer

摘要: Copy List with Random PointerA linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.题目意思:深拷贝一个给定的带random指针的链表,这个random指针可能会指向其他任意一个节点或者是为null。(又是链表啊啊啊啊啊啊啊!!!!!!!!Orz……)解题思路:在每个原来节点的后面插入一个新节点(la 阅读全文

posted @ 2014-04-02 21:38 Allen Blue 阅读(156) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Add Two Numbers

摘要: 链表相加You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8题目意思:给定两个链表,返回其相加 阅读全文

posted @ 2014-04-02 17:54 Allen Blue 阅读(1069) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Permutations

摘要: 全排列Given a collection of numbers, return all possible permutations.For example,[1,2,3]have the following permutations:[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2], and[3,2,1].题目意思:给定一个集合,求全排列。解题思路:一般的话,有两种思路可以考虑。递归和DFS遍历树。这里我只用了递归的方法,关于怎么建一棵树然后DFS,可以参考 这里。这对于练习对递归的理解真是个不错的题目。以[1,2,3]举例,可以用纸笔画一画,分别以1,2,3为 阅读全文

posted @ 2014-04-02 16:43 Allen Blue 阅读(325) 评论(0) 推荐(0) 编辑

2014年4月1日

【各种排序系列之】归并排序

摘要: 转载自:白话经典算法系列之五 归并排序的实现普通的合并两个数组的代码:O(n) 1 //将有序数组a[]和b[]合并到c[]中 2 void MemeryArray(int a[], int n, int b[], int m, int c[]) 3 { 4 int i, j, k; 5 6 i = j = k = 0; 7 while (i < n && j < m) 8 { 9 if (a[i] < b[j])10 c[k++] = a[i++];11 else12 c[k++... 阅读全文

posted @ 2014-04-01 21:18 Allen Blue 阅读(171) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Candy

摘要: 分糖果There areNchildren standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their neighbors.What is the minimum candies you 阅读全文

posted @ 2014-04-01 21:09 Allen Blue 阅读(168) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Minimum Window Substring

摘要: 找出包含子串的最小窗口Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S="ADOBECODEBANC"T="ABC"Minimum window is"BANC".Note:If there is no such window in S that covers all characters in T, retur 阅读全文

posted @ 2014-04-01 20:34 Allen Blue 阅读(250) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Partition List

摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,题目意思为:给定一个链表和一个数,把这个链表中比这个数小的数全放 阅读全文

posted @ 2014-04-01 20:17 Allen Blue 阅读(191) 评论(0) 推荐(0) 编辑

2013年12月10日

【Java之】多线程学习笔记

摘要: 最近在学习thinking in java(第三版),本文是多线程这一章的学习总结。-----------------------------------------------------------------------------------------------------------------------------------------------------------内容:创建线程的两种方法,继承Thread和implements Runnable接口。设置线程的优先权Priorities。后台线程。线程的join方法。介绍两种匿名内部类的实现。有响应的用户界面实例。不 阅读全文

posted @ 2013-12-10 17:07 Allen Blue 阅读(228) 评论(0) 推荐(0) 编辑

2013年10月30日

【Java】使用Runtime执行其他程序

摘要: 1 public class ExecDemo{ 2 public static void main(String[] args) { 3 Runtime r = Runtime.getRuntime(); 4 Process p = null; 5 try { 6 p = r.exec("notepad"); 7 //p=Runtime.getRuntime().exec("cmd /c start D://2.doc"); 8 Thr... 阅读全文

posted @ 2013-10-30 09:32 Allen Blue 阅读(236) 评论(0) 推荐(0) 编辑

2013年10月28日

【各种排序系列之】快速排序法

摘要: 基本思想:从待排序列中任取一个元素 (例如取第一个) 作为中心,所有比它小的元素一律前放,所有比它大的元素一律后放,形成左右两个子表。然后再对各子表重新选择中心元素并依此规则调整,直到每个子表的元素只剩一个。此时便为有序序列了。时间效率:O(nlogn) —因为每趟确定的元素呈指数增加空间效率:O(logn)—因为递归要用栈(存每层low,high和pivot)C语言实现: 1 //首先定义数据类型 2 #define MAXSIZE 20 //示例的小顺序表的最大长度 3 typedef int KeyType; //定义关键字类型为整数类型 4 typedef struct { 5 ... 阅读全文

posted @ 2013-10-28 22:10 Allen Blue 阅读(285) 评论(0) 推荐(0) 编辑

导航