- 博客(199)
- 资源 (5)
- 收藏
- 关注
原创 谷歌的三篇论文
传说中的谷歌三篇论文MapReduce: Simplified Data Processing on Large ClustersThe Google file systemBigtable: A Distributed Storage System for Structured Data谷歌学术立搜可下。
2014-12-17 22:14:01
2058
原创 Nginx的第一个模块-Hello World
麻雀虽小,五脏俱全,小小的Hello World盛行于程序世界,就在于其代码虽短,但要真正运行起来,需要我们略通基本语法,稍懂编译运行环境,知晓操作过程,最后,还有一颗持之以恒,不怕折腾的心。前一阵子跑通了Nginx的Hello World程序,今天重温了一遍就顺便写篇博客,记录下来,好记性不如烂笔头,方便以后查阅。
2014-08-25 21:34:56
2806
原创 第五十一题 和为n 连续正数序列
51.和为n 连续正数序列。题目:输入一个正数n,输出所有和为n 连续正数序列。例如输入15,由于1+2+3+4+5=4+5+6=7+8=15,所以输出3 个连续序列1-5、4-6 和7-8。代码如下:public static void findSeqSum(int sum) { int begin=1,end=2,mid=sum/2,curSum=begin+end;
2014-08-23 23:07:43
829
原创 leetcode 刷题之路 95 N-Queens II
N皇后问题的变种,要求直接输出N皇后的解法数目。这道题可以在N-Queens I的基础上增加计数功能,在每求得一个成功的解时(行数为N时)使计数变量递增即可。题目不要求输出具体的解法,因此可以做一点优化,使用position数组用来表示皇后的位置,position[i]的值表示第i行的皇后所处的列,这样子省却字符串数组的开销同时判断是否合法的isValid函数也更加简洁。
2014-08-17 11:52:12
847
原创 leetcode 刷题之路 94 N-Queens
非常经典的N皇后问题:在一个N*N的棋盘上放置N个皇后,每行一个并使其不能互相攻击(同一行、同一列、同一对角线上的皇后都会自动攻击)。
2014-08-17 10:51:18
860
原创 leetcode 刷题之路 92 Climbing Stairs
一个台阶总共有n级,如果一次可以跳1级,也可以跳2级,求总共有多少总跳法。
2014-08-16 20:46:56
1235
1
原创 leetcode 刷题之路 91 Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]
2014-08-13 21:38:55
718
原创 leetcode 刷题之路 90 Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers
2014-08-13 21:29:31
863
原创 leetcode 刷题之路 89 Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2014-08-13 17:11:24
815
原创 leetcode 刷题之路 88 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2014-08-13 16:36:20
751
原创 leetcode 刷题之路 87 Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2014-08-13 16:17:59
770
原创 leetcode 刷题之路 86 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2014-08-13 15:55:43
709
原创 leetcode 刷题之路 85 Merge Two Sorted Lists
erge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.合并两个有序链表,合并后的链表仍然有序。
2014-08-13 15:34:45
754
原创 leetcode 刷题之路 84 Single Number II
给定一个包含n个整数的数组,除了一个数出现一次外所有的整数均出现三次,找出这个只出现一次的整数。
2014-08-13 13:46:36
957
原创 leetcode 刷题之路 83 Maximum Subarray
思路:从左向右遍历数组元素相加求和得到和sum,若sum小于0,必然会对总的和有损耗,因此将sum重置为0,从当前位置继续重复上述过程,直到数组结束,与此同时设置max变量记录求和过程中遇到的最大值。执行完上述过程,判断max等于0(max初值为0),若大于0,max为所求结果,返回max。若仍然等于0说明求和过程中未出现过正数,数组中全是负数或0,此时数组最大和就是数组中最大的最
2014-08-13 13:27:19
792
原创 leetcode 刷题之路 82 Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2014-08-13 13:18:56
905
原创 leetcode 刷题之路 81 Populating Next Right Pointers in Each Node
Populate each next pointer to point to its next right node. 二叉树的结构体里增加了next指针,编写程序,将二叉树里每个节点的next指针指向它右边的节点。
2014-08-13 09:56:45
761
原创 状态模式
在软件设计中经常会遇到这样的对象转移的条件表达式过于复杂的情况,这时可以采用if else或者switch case等语句进行处理,但是这样做的弊端就在于每增加一次状态,都需要对以前的代码进行修改,这不符合面向对象的开闭原则。此时更好的方法就是将状态的判断逻辑转移到表示不同状态的一系列类中,这就是今天要介绍的状态模式。状态模式的定义,允许一个对象在其内部状态改变时改变它的行为。状态模式的U
2014-08-12 23:01:31
887
2
原创 leetcode 刷题报告 80 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using e
2014-08-12 20:03:16
620
原创 leetcode 刷题之路 77 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1
2014-08-11 17:21:29
983
原创 leetcode 刷题之路 76 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.删除排序链表中重复的节点,删除操作
2014-08-11 15:47:19
771
原创 leetcode 刷题之路 75 Plus One
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.用vector表示一个数,在这个数上j
2014-08-10 19:25:32
908
原创 leetcode 刷题之路 74 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.从前序遍历结果和中序遍历结果中
2014-08-10 18:26:02
637
原创 leetcode 刷题之路 73 Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You ma
2014-08-10 17:55:39
675
原创 leetcode 刷题之路 72 Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2014-08-10 16:32:26
563
原创 leetcode 刷题之路 71 Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),
2014-08-10 16:00:11
576
原创 leetcode 刷题之路 70 earch Insert Position 二分查找插入位置
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 in the array.
2014-08-10 15:46:55
843
原创 leetcode 刷题之路 69 Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2014-08-10 14:36:00
484
原创 leetcode 刷题之路 68 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 costs cost[i] of gas to travel from station i to
2014-08-10 13:17:54
751
原创 leetcode 刷题之路 67 Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t
2014-08-10 11:06:44
461
原创 leetcode 刷题之路 66 Path Sum II
给定一个二叉树和数字sum,输出二叉树中从根节点到叶子节点所有路径中和等于sum的路径。
2014-08-10 10:25:08
765
原创 leetcode 刷题之路 65 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f
2014-08-09 23:50:24
555
原创 leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.给出二叉树的中序遍历和后序遍历结果,恢复出二叉树。后序遍历序列的最后一个元素值是二叉树的根节点的值,查找
2014-08-09 23:06:54
776
原创 leetcode 刷题之路 63 Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).zigzag层序遍历树For example:Given binary
2014-08-09 22:05:08
743
原创 leetcode 刷题之路 62 Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.求树的最大深度。树的最大深度d
2014-08-09 20:56:36
509
原创 leetcode 刷题之路 61 Sort List
Sort a linked list in O(n log n) time using constant space complexity.题目要求,对链表进行排序,要求时间buzad
2014-08-09 20:45:57
550
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人