自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(225)
  • 收藏
  • 关注

原创 【校招靠谱内推】

校招内推

2022-08-09 19:48:06 247 2

原创 1019. Next Greater Node In Linked List(链表)

https://leetcode.com/problems/next-greater-node-in-linked-list/、题目:求每个节点后面比他大的节点思路:stack中维持递降的顺序,批量求解,时间复杂度: O(n), 空间复杂度O(n)代码class Solution {public: vector<int> nextLargerNodes(ListNod...

2020-02-09 13:07:19 366

原创 1290. Convert Binary Number in a Linked List to Integer(链表)

https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/题目:将二进制转换为整数比较简单,直接放代码:func getDecimalValue(head *ListNode) int { return func(ret int) int { for head != ni...

2020-02-09 11:38:20 263

原创 921. Minimum Add to Make Parentheses Valid

链接:https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/题目:求最少括号匹配数目思路:出现 ’)’ 并且’(’数目大于0,则匹配,需要匹配的数目减1代码func minAddToMakeValid(S string) int { var ( left = 0 ret = 0...

2020-01-29 11:29:03 141

原创 1217. Minimum Cost to Move Chips to The Same Position(贪心)

链接:https://leetcode.com/problems/minimum-cost-to-move-chips-to-the-same-position/思路:位置相差2不产生消耗,所以奇数或者偶数位置之间是等价的,实际只要得出哪个哪个数量少就行代码:func minCostToMoveChips(position []int) int { var ( even_number = 0 position_len = len(position) )

2021-04-11 16:47:54 200

原创 秋招终结贴

一些情况从2018年3月开始找实习,到2019年2月结束找工作,整个过程比较漫长。不过也顺利通过了很多公司的面试。薪资范围:22w~44w 百度,蚂蚁金服(阿里),腾讯 京东,网易游戏,字节跳动 商汤,科大讯飞 硅谷SunnyKing区块链团队 BIGO,日志易,深信服比较想去深圳,加上腾讯...

2020-02-29 21:40:05 3982 5

原创 606. Construct String from Binary Tree(Tree)

链接:https://leetcode.com/problems/construct-string-from-binary-tree/题目:构造先序遍历字符串思路:对于每个节点,5种情况NULL 1 1 1 1 /...

2019-02-15 20:57:59 348 1

原创 107. Binary Tree Level Order Traversal II(Tree)

链接:https://leetcode.com/problems/binary-tree-level-order-traversal-ii/题目: 自底向上层次遍历二叉树思路:层次遍历,最后再交换。class Solution {public: vector&lt;vector&lt;int&gt;&gt; levelOrderBottom(TreeNode* root) { ...

2019-02-14 16:41:08 204

原创 Tstress

用几天时间写了个压测工具,代码链接:Githubhttps://github.com/tangyuanzong/Tstress/tree/master参数说明: -T 总线程数 -S HTTP总连接数 -C 并发连接数 H / S 每秒建立的HTTP数目...

2019-01-25 21:15:36 514

原创 297. Serialize and Deserialize Binary Tree (Tree)

链接:https://leetcode.com/problems/serialize-and-deserialize-binary-tree/题目:自定义二叉树序列化与反序列化协议。思路:自定义序列化格式:{root-&gt;val:root-&gt;left-&gt;val,root-&gt;right-&gt;val}例如 1 / \ 2 3 / \...

2019-01-16 11:35:01 333

原创 145. Binary Tree Postorder Traversal(Tree)

链接:https://leetcode.com/problems/binary-tree-postorder-traversal/题目:二叉树后序遍历思路:题目很简单,但是却是Hard难度。。。。。。。。代码:class Solution {public: void post(TreeNode* root){ if(!root) return; ...

2019-01-14 11:46:32 238

原创 429. N-ary Tree Level Order Traversal(Tree)

链接:https://leetcode.com/problems/n-ary-tree-level-order-traversal/题目:N叉树的层次遍历思路:与二叉树层次遍历相似代码:class Solution {public: vector&lt;vector&lt;int&gt;&gt; levelOrder(Node* root) { ...

2019-01-14 11:38:01 155

原创 102. Binary Tree Level Order Traversal(Tree)

链接:https://leetcode.com/problems/binary-tree-level-order-traversal/题目:二叉树层次遍历思路:BFS代码:class Solution {public: vector&lt;vector&lt;int&gt;&gt; levelOrder(TreeNode* root) { v...

2019-01-14 11:34:37 138

原创 653. Two Sum IV - Input is a BST(Tree)

链接:https://leetcode.com/problems/two-sum-iv-input-is-a-bst/题目: 判断BST中是否有两个原始的和等于k思路: BST中序遍历的结果为有序数组;然后再扫描数组判断即可(复杂度O(n))代码:class Solution {public: void inorder(TreeNode* root){ if(...

2019-01-13 22:40:50 149

原创 590. N-ary Tree Postorder Traversal(Tree)

链接:https://leetcode.com/problems/n-ary-tree-postorder-traversal/题目:求n叉树的后续遍历思路:与二叉树的后续遍历类似。代码:class Solution {public: void post(Node* root){ if(!root) return; f...

2019-01-13 20:35:42 181

原创 513. Find Bottom Left Tree Value(Tree)

链接:https://leetcode.com/problems/find-bottom-left-tree-value/题目:求二叉树最底层的最左边元素思路: 层次遍历代码:class Solution {public: int findBottomLeftValue(TreeNode* root) { int val = root-&gt;val;...

2019-01-13 20:21:18 170

原创 105. Construct Binary Tree from Preorder and Inorder Traversal(Tree)

链接:https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/题目:已知前序和中序遍历,构造原二叉树。思路:与前一题类似:https://blog.csdn.net/tangyuanzong/article/details/86261711根节点在前序遍历的第一个位置,在中...

2019-01-11 13:54:50 137

原创 106. Construct Binary Tree from Inorder and Postorder Traversal(Tree)

链接:https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/题目:给定二叉树中序和后序遍历,构造出原二叉树。思路:根节点在后序遍历的最后一个位置,在中序遍历的中间位置。通过后序遍历找到根节点,然后通过中序遍历找出左右子树,然后递归构造。例如给定样例:inorder =...

2019-01-10 22:54:06 195

原创 108. Convert Sorted Array to Binary Search Tree(Tree)

链接:https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/题目:将有序数组转换成BST思路:对于当前区间,新建节点,节点值为数组当前区间中间的元素,然后后续遍历,递归构建代码:class Solution {public: TreeNode* order(vector&lt;int&gt...

2019-01-01 10:40:24 131

原创 230. Kth Smallest Element in a BST(Tree)

链接:https://leetcode.com/problems/kth-smallest-element-in-a-bst/题目:求BST第k小元素思路:中序遍历,然后计数。代码:class Solution {public: void order(TreeNode *root,int k){ if(!root || num &gt; k) return; ...

2019-01-01 10:18:19 161

原创 199. Binary Tree Right Side View(Tree)

题目:https://leetcode.com/problems/binary-tree-right-side-view/思路:层次遍历,每次统计当前层的节点个数(cur_low)和下一层的节点个数(next_low),当cur_low ==1 时,找到一个最右节点,然后更新cur_low(cur_low = next_low)。代码:class Solution {public: ...

2018-12-30 11:20:31 126

原创 129. Sum Root to Leaf Numbers(Tree)

链接:https://leetcode.com/problems/sum-root-to-leaf-numbers/题目:一条roo-&gt;leaf路径代表一个整数,求所有整数之和思路:先序遍历代码:class Solution {public: void pre(TreeNode *root,int sum){ if(!root) return; ...

2018-12-30 11:05:31 138

原创 98. Validate Binary Search Tree (Tree)

题目链接:https://leetcode.com/problems/validate-binary-search-tree/submissions/题目描述:判断BST是否合法。思路:中序遍历;对于BST来说,中序遍历的结果是一个递增的序列,所以在递增的过程中判断即可。代码:class Solution {public: void order(TreeNode *root){...

2018-12-29 12:43:58 129

原创 114. Flatten Binary Tree to Linked List(Tree)

链接:https://leetcode.com/problems/flatten-binary-tree-to-linked-list/题目:将二叉树序列化为链表思路:先序遍历,保存一个全局的newroot,对于当前节点root:暂存左右子节点,然后将newroot-&gt;right = root;newroot-&gt;left = NULL;newroot = root;代码:c...

2018-12-21 15:33:21 171

原创 897. Increasing Order Search Tree(Tree)

链接:https://leetcode.com/problems/increasing-order-search-tree/题目:将原二叉搜索树进行调整,使得每个节点只有右子节点。例如:Example 1:Input: [5,3,6,2,4,null,8,1,null,null,null,7,9] 5 / \ 3 6 / \ \ 2...

2018-12-20 16:33:50 350

原创 515. Find Largest Value in Each Tree Row(Tree)

链接:https://leetcode.com/problems/find-largest-value-in-each-tree-row/题目:求二叉树每一层的最大值;思路:采用层次遍历方式。代码:class Solution {public: vector&lt;int&gt; largestValues(TreeNode* root) { ve...

2018-12-20 15:54:22 197

原创 700. Search in a Binary Search Tree(Tree)

链接:https://leetcode.com/problems/search-in-a-binary-search-tree/题目:BST的查找,直接查找即可。class Solution {public: TreeNode* searchBST(TreeNode* root, int val) { if(!root) ...

2018-12-15 19:10:35 260

原创 23. Merge k Sorted Lists(链表)

题目:https://leetcode.com/problems/merge-k-sorted-lists/合并n个排序链表,直接合并即可。class Solution {public: ListNode* mergeKLists(vector&amp;lt;ListNode*&amp;gt;&amp;amp; lists) { ListNode * head = new Li...

2018-12-15 18:56:46 207

原创 109. Convert Sorted List to Binary Search Tree(Tree)

题目:https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/描述:将排序链表转换为平衡的二叉搜索树思路: 后序遍历,例如:[-10,-3,0,5,9] [-10,-3,0,5,9] mid: 3 len...

2018-12-05 20:44:39 204

原创 142. Linked List Cycle II(链表)

https://leetcode.com/problems/linked-list-cycle-ii/description/题目:如果链表有环,返回环的入口,负责返回NULL.思路:快慢指针,考虑下面的链表环,其中4-&gt;2表示4的下一元素为2。1-&gt;2-&gt;3-&gt;4-&gt;2。ft st flag1 1 ...

2018-05-23 21:45:47 312

原创 19. Remove Nth Node From End of List(链表)

https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/题目:删除倒数第n个节点(遍历只能一趟)思路:双指针例如:1-&gt;2-&gt;3-&gt;4-&gt;5, n = 2代码原理如下t1的值 t1-&gt;next的值 t的值 n的值0 ...

2018-05-07 22:17:34 407

原创 100. Same Tree(Tree)

https://leetcode.com/problems/same-tree/description/题目:判断2课二叉树是否相同思路:任何一种遍历都可以,我采用的是先序遍历,然后直接比较相应位置的元素即可。代码:class Solution {public: bool sameTree(TreeNode* p , TreeNode* q){ if(...

2018-05-02 23:53:31 179

原创 617. Merge Two Binary Trees(Tree)

https://leetcode.com/problems/merge-two-binary-trees/description/题目:合并2棵二叉树思路:采用后序遍历的方法,分为3种情况:1 如果t1非空并且t2非空,则t1加上t2的值,返回t1,否则直接返回t12 t1为空且t2非空,返回t23 t1和t2都为空,返回NULL代码:class Solution {pu...

2018-05-02 00:18:09 214

原创 328. Odd Even Linked List(链表)

https://leetcode.com/problems/odd-even-linked-list/description/题目:将链表奇数位上的节点放到偶数位上的节点前面。思路:分别构造两条链表:奇数位的链表,偶数位的链表,最后一个奇数位节点的下一个节点为偶数位节点的开头 空间复杂度O(1),时间复杂度O(n)class Solution {public...

2018-05-01 00:36:20 296

原创 111. Minimum Depth of Binary Tree(Tree)

https://leetcode.com/problems/minimum-depth-of-binary-tree/description/题目:求二叉树的最小深度思路:直接用BFSclass Solution {public: int minDepth(TreeNode* root) { int re = 1; if(!root) retu...

2018-04-29 17:09:17 152

原创 99. Recover Binary Search Tree(Tree)

https://leetcode.com/problems/recover-binary-search-tree/description/题目:BST中,某2个节点交换了位置,求出正确的BST。最简单的解法:O(n)的空间复杂度,两次中序遍历。class Solution {public: vector&lt;int&gt;v; int index = 0; ...

2018-04-24 13:49:51 449

原创 94. Binary Tree Inorder Traversal(Tree)

https://leetcode.com/problems/binary-tree-inorder-traversal/description/题目:求二叉树的中序遍历思路:直接中序遍历。class Solution {public: vector&lt;int&gt;v; void inorder(TreeNode *root){ if(!ro...

2018-04-24 12:53:01 192

原创 110. Balanced Binary Tree(Tree)

https://leetcode.com/problems/balanced-binary-tree/description/题目:判断二叉树是不是平衡树思路:采用后续遍历的方式,求出左右子节点的返回值,如果左子树的返回值为-1,或者右子树的返回值为-1,或者左右子树的返回值之差的绝对值大于1,则返回-1 。否则返回max(左子树高度,右子树高度)+1。class Solution...

2018-04-18 17:16:32 170

原创 226. Invert Binary Tree(Tree)

https://leetcode.com/problems/invert-binary-tree/description/题目:将二叉树进行翻转思路:使用BFS进行遍历,然后交换每个结点的左右子节点。class Solution {public: TreeNode* invertTree(TreeNode* root) { if(!root) re...

2018-04-16 21:35:41 120

原创 637. Average of Levels in Binary Tree(Tree)

https://leetcode.com/problems/average-of-levels-in-binary-tree/description/题目:求每一层元素的平均值思路:BFS遍历class Solution {public: vector&lt;double&gt; averageOfLevels(TreeNode* root) { ve...

2018-04-15 23:35:41 197

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除