- 博客(14)
- 收藏
- 关注
原创 Leetcode 653. Two Sum IV - Input is a BST
Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3 6 / \ ...
2018-11-04 00:30:37 185
原创 Leetcode 454. 4Sum II
问题Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same ...
2018-10-20 23:13:23 177
原创 Leetcode 18. 4Sum
问题Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum o...
2018-08-31 21:22:48 160
原创 LeetCode 15. 3Sum
问题Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not...
2018-08-31 13:46:33 130
原创 归并排序的优化
归并排序的时间复杂度为, 插入排序的时间复杂度为, 当需要排序的数组足够长时,归并排序肯定比插入排序更快,但当数组长度比较小的时候,常量因子起主导作用,由于插入排序的常量因子比较小,插入排序比归并排序更快。所以有一个常见的对归并排序的优化:当递归排序的子问题变得足够小时,不继续递归调用归并排序,而是直接调用插入排序。有两种做法:自顶向下,指定需要使用插入排序的子问题的大小。 自底向上...
2018-08-14 09:10:54 1282 1
原创 Leetcode 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same...
2018-08-13 01:24:14 158
原创 汉诺塔问题
汉诺塔(港台:河内塔)是根据一个传说形成的数学问题:有三根杆子A,B,C。A杆上有 N 个 (N>1) 穿孔圆盘,盘的尺寸由下到上依次变小。要求按下列规则将所有圆盘移至 C 杆:每次只能移动一个圆盘;大盘不能叠在小盘上面。提示:可将圆盘临时置于 B 杆,也可将从 A 杆移出的圆盘重新移回 A 杆,但都必须遵循上述两条规则。问:如何移?最少要移动多少次? 解析解决汉...
2018-07-28 17:04:15 552
原创 Python Exception 错误信息输出机理
当遇到一个如下的exception时,最后一行错误信息是从何而来的呢? >>> 2 / 0 Traceback (most recent call last): File “”, line 1, in ZeroDivisionError: integer division or modulo by zero
2016-03-04 23:28:39 1193
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人