上一页 1 ··· 5 6 7 8 9 10 11 12 下一页

2014年8月19日

Gas Station

摘要: There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it cost 阅读全文

posted @ 2014-08-19 20:46 bug睡的略爽 阅读(247) 评论(0) 推荐(0) 编辑

Reverse Words in a String

摘要: Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the". click to show clarification. 阅读全文

posted @ 2014-08-19 18:26 bug睡的略爽 阅读(138) 评论(0) 推荐(0) 编辑

Maximum Subarray

摘要: Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array 阅读全文

posted @ 2014-08-19 16:17 bug睡的略爽 阅读(401) 评论(0) 推荐(0) 编辑

2014年8月16日

Permutations系列

摘要: 一. 全排列递归算法 1. 数据没有重复的情况下 算法:每个元素依次与后面的数进行交换 例子:假设元素为123,则递归交换事例如下: 2. 数据有重复的情况下、 算法:在没有数据重复的全排列下,交换需要加上前提条件,即元素应该和后面没有重复出现的数字进行交换,即当访问到第k个元素的时候,如果 [k, 阅读全文

posted @ 2014-08-16 16:05 bug睡的略爽 阅读(171) 评论(0) 推荐(0) 编辑

2014年8月15日

海量数据等概率选取问题

摘要: 1、问题定义可以简化如下:在不知道文件总行数的情况下,如何从文件中随机的抽取一行,并且每行被抽中的概率相等? 首先想到的是我们做过类似的题目吗?当然,在知道文件行数的情况下,我们可以很容易的用C运行库的rand()函数随机的获得一个行数,从而随机的取出一行,但是,当前的情况是不知道行数,这样如何求呢... 阅读全文

posted @ 2014-08-15 20:52 bug睡的略爽 阅读(190) 评论(0) 推荐(0) 编辑

2014年8月14日

Sort List系列

摘要: 在严老师的数据结构书上学习了各种排序算法,比如插入排序,选择排序,堆排序,快速排序,归并排序等,不过书上代码的应用场景均是底层结构是顺序存储的情况,即数组。 今天总结下对于单链表,常用的排序算法能否使用。由于希尔排序、堆排序、计数排序都要求随机访问,而单链表只能顺序访问,故这 3 种是不能用于单向链 阅读全文

posted @ 2014-08-14 22:20 bug睡的略爽 阅读(196) 评论(0) 推荐(0) 编辑

Linked List Cycle系列

摘要: 首先讨论下有环单链表相关问题 1. 判断单链表是否有环 使用slow,fast指针从头开始扫描链表,slow指针每次走一步,fast指针每次走两步,如果链表有环,那么fast指针一定会追上slow指针,否则,fast指针会遇到null。 2. 求有环单链表的环长 设环长为R,当fast,slow指针 阅读全文

posted @ 2014-08-14 15:49 bug睡的略爽 阅读(163) 评论(0) 推荐(0) 编辑

2014年8月12日

Construct Binary Tree系列

摘要: Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may ass 阅读全文

posted @ 2014-08-12 23:38 bug睡的略爽 阅读(209) 评论(0) 推荐(0) 编辑

Binary Tree Level Order Traversal系列

摘要: Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level) 阅读全文

posted @ 2014-08-12 22:25 bug睡的略爽 阅读(135) 评论(0) 推荐(0) 编辑

Binary Tree Traversal系列

摘要: Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 阅读全文

posted @ 2014-08-12 21:00 bug睡的略爽 阅读(129) 评论(0) 推荐(0) 编辑

上一页 1 ··· 5 6 7 8 9 10 11 12 下一页

导航