- 博客(17)
- 收藏
- 关注
原创 如何解决socket通信server端的address already in use的错误
最近用Python 的socketserver框架进行TCP/IP socket服务器端的项目。但是服务器主程序正常退出以后,再启动该服务器主程序就会遇到Address already in use这个错误这个错误其实是由bind()函数抛出的。但是这个错误绝对不是由于服务器程序退出的时候忘记close socket造成的。http://www.ibm.com/developerwor
2016-01-05 11:53:20 4548
转载 Leetcode: Dungeon Game
分析:At first glance, this problem bears a large resemblance to the "Maximum/Minimum Path Sum" problem. However, a path with maximum overall health gain does not guarantee the minimum initial he
2015-03-16 00:47:04 399
原创 LeetCode: linked list cycle I and II
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?这道题非常常见,http://blog.csdn.net/hf81970/article/details/14169655 这篇文章讲的非常全面。分析简单明
2015-03-15 18:47:27 248
原创 Leetcode: Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.
2015-03-15 18:02:07 363
原创 Leetcode: Repeated DNA Sequence
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri
2015-03-15 15:01:46 373
原创 Leetcode: Roman To Integer
这道题本来很简单,可是需要注意的是从细节上进行性能改进。一开始我是用Map来存储罗马字母和数字的对应关系,结果发现性能比较差。而改为switch,并且将之写成子函数,并将函数设置Inline,性能得到改进。因此,如果需要建立映射关系的时候,如果映射的组数比较少的时候,应该尝试使用switch来建立映射关系。如果子函数较小,且被频繁调用,那么应该将该函数设置为inline。这样函数代码会内嵌到代
2015-03-14 00:23:34 242
原创 LeetCode: sudoku solver and valid sudoku
problem: valid sudokuDetermine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
2015-03-11 19:26:24 343
原创 LeetCode: Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2015-03-10 13:48:14 535
原创 LeetCode: Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2015-03-09 22:34:44 509
原创 LeetCode: Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101
2015-03-09 18:07:54 244
原创 Leetcode: Permutation Sequence
题目:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""21
2015-03-06 16:43:43 243
原创 Leetcode: Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as
2015-03-06 15:41:33 207
原创 leetcode: Palindrome Partitioning
题目Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [
2015-03-04 22:33:39 275
原创 LeetCode: Construct Binary Tree from Inorder and Postorder Traversal
问题:Given inorder and postorder traversal of a tree, construct the binary tree.解答:这是非常常规的递归问题。需要注意的是递归函数参数的设计。如果设置为题目早前设定的TreeNode *buildTree(vector &inorder, vector &postorder),那么在大数据情况下 ,会出现调用栈
2015-03-04 19:48:42 210
原创 leetcode: Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb
2015-02-18 02:19:47 194
转载 LeetCode : Container With Most Water
i, j分别从头尾开始遍历,面积 area = min(height[j], height[i]) * (j-i),当height[i] class Solution {public: int maxArea(vector &height) { int water = 0; if(height.size() < 2)
2015-02-16 21:01:37 211
转载 LeetCode:Trapping Rain Water
算法很简单,核心思想是:对某个值A[i]来说,能trapped的最多的water取决于在i之前最高的值leftMostHeight[i]和在i右边的最高的值rightMostHeight[i]。(均不包含自身)。如果min(left,right) > A[i],那么在i这个位置上能trapped的water就是min(left,right) – A[i]。有了这个想法就好办了,第一遍从左到
2015-02-15 20:32:32 387
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人