摘要:
Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2... 阅读全文
摘要:
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
摘要:
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
摘要:
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ... 阅读全文
摘要:
1最容易想到的递归调用 1 bool isSameTree(TreeNode *r1, TreeNode *r2) 2 { 3 if(r1 == NULL && r2 == NULL) return true; //终止条件 4 if(r1 == NULL || r2 == NULL... 阅读全文
摘要:
前中后遍历 递归版 1 /* Recursive solution */ 2 class Solution { 3 public: 4 vector preorderTraversal(TreeNode *root) { 5 6 vector resul... 阅读全文
摘要:
题目的关键是要让新链表和原有链表发送关联,可以通过这种关联来设置新链表的random pointer思路:将新链表的元素插入到原有链表元素的后面,如下图所示,就可以根据原有链表的radom->next 就是新链表的random指针所以分3步骤:1 新元素插入2 设置新链表的random3 拆分大链表... 阅读全文
摘要:
第一种方法,暴力求解,从当前向左右两个方向扫描比自己小的,然后计算面积,时间复杂度O(n^2)code如下,但是在LeetCode上回超时。 1 class Solution { 2 public: 3 int largestRectangleArea(vector &height) { 4... 阅读全文
摘要:
第一种方法,用栈实现,最容易想到,也比较容易实现,每次碰到‘)’时update max_len,由于要保存之前的‘(’的index,所以spacecomplexity 是O(n) 1 // 使用栈,时间复杂度 O(n),空间复杂度 O(n) 2 class Solution { 3 publ... 阅读全文