算法
Smiling_Wang
这个作者很懒,什么都没留下…
展开
-
洗牌问题——偶数张扑克牌,分成两等份, 洗牌多少次回到原来顺序?
使用群论,将洗牌问题从复杂繁琐的编程问题变为简洁优雅的数学问题原创 2016-09-11 17:01:59 · 1979 阅读 · 1 评论 -
汉诺塔问题
汉诺塔(港台:河内塔)是根据一个传说形成的数学问题:有三根杆子A,B,C。A杆上有 N 个 (N>1) 穿孔圆盘,盘的尺寸由下到上依次变小。要求按下列规则将所有圆盘移至 C 杆:每次只能移动一个圆盘;大盘不能叠在小盘上面。提示:可将圆盘临时置于 B 杆,也可将从 A 杆移出的圆盘重新移回 A 杆,但都必须遵循上述两条规则。问:如何移?最少要移动多少次? 解析解决汉...原创 2018-07-28 17:04:15 · 544 阅读 · 0 评论 -
归并排序的优化
归并排序的时间复杂度为, 插入排序的时间复杂度为, 当需要排序的数组足够长时,归并排序肯定比插入排序更快,但当数组长度比较小的时候,常量因子起主导作用,由于插入排序的常量因子比较小,插入排序比归并排序更快。所以有一个常见的对归并排序的优化:当递归排序的子问题变得足够小时,不继续递归调用归并排序,而是直接调用插入排序。有两种做法:自顶向下,指定需要使用插入排序的子问题的大小。 自底向上...原创 2018-08-14 09:10:54 · 1231 阅读 · 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 · 138 阅读 · 0 评论 -
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 · 127 阅读 · 0 评论 -
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 · 134 阅读 · 0 评论 -
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 · 174 阅读 · 0 评论 -
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 · 174 阅读 · 0 评论