摘要:
思路: 一般我们会想到用排序,然后找出中间那个值,此值就是超过一半的那个数 但是这样的时间复杂度一般为O(nlogn) 其实有一个比较巧妙的办法,时间复杂度为O(n) 1,遍历这个数组,如果之前一个数字和下一个数字重复则+1,否则-1 这样最终留下的数就是那个超过一半的那个数 代码 void mor 阅读全文
posted @ 2020-11-03 23:20
冬马党
阅读(232)
评论(0)
推荐(0)
摘要:
bool verifySequenceOfBST(int sequence[],int length){ if(sequence == NULL || length == 0){ return false; } int root = sequence[length - 1]; int i =0 ; 阅读全文
posted @ 2020-11-03 21:58
冬马党
阅读(219)
评论(1)
推荐(0)
摘要:
#include <iostream> #include <string> using namespace std; template<typename T> class StackWithMin { stack data; stack minStack; void push(const T& va 阅读全文
posted @ 2020-11-03 18:26
冬马党
阅读(98)
评论(0)
推荐(0)
摘要:
镜像树,如图 思路: 利用递归的思想,如果一颗树有左右节点,则进行交换,有一个节点为空则退出递归 struct BinaryTreeNode { int val; BinaryTreeNode* left; BinaryTreeNode* right; }; void mirrorRecursive 阅读全文
posted @ 2020-11-03 17:51
冬马党
阅读(181)
评论(0)
推荐(0)

浙公网安备 33010602011771号