![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
赵小越
内心戏丰富的的女深井吧
展开
-
leetcode(160):Intersection of Two Linked Lists
题目:Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists:A: a1 → a2原创 2018-01-29 22:06:31 · 146 阅读 · 0 评论 -
leetcode(108):Convert Sorted Array to Binary Search Tree
题目: Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of t原创 2018-03-15 12:59:29 · 118 阅读 · 0 评论 -
leetcode(110):Balanced Binary Tree
题目: Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node never ...原创 2018-03-15 18:43:26 · 137 阅读 · 0 评论 -
leetcode(617):Merge Two Binary Trees
题目要求: Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new bina...原创 2018-03-01 21:00:09 · 148 阅读 · 0 评论 -
leetcode(253):Lowest Common Ancestor of a Binary Search Tree
题目: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee原创 2018-03-16 20:50:05 · 133 阅读 · 0 评论 -
leetcode(257):Binary Tree Paths
题目: Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]题目分析:其实这类型题采用的递归方法,递归最主要的是考虑原创 2018-03-16 21:56:49 · 133 阅读 · 0 评论 -
leetcode(669):Trim a Binary Search Tree
题目:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the res原创 2018-03-03 20:45:05 · 156 阅读 · 0 评论 -
leetcode(404):Sum of Left Leaves
题目:Find the sum of all left leaves in a given binary tree. example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Ret...原创 2018-03-04 11:36:36 · 198 阅读 · 0 评论 -
leetcode(226):Invert Binary Tree
题目要求: 题目分析:还是利用树的递归的实现方法,也就是找一个模式,从根出发,然后执行操作,什么情况下停止操作,返回什么值,然后递归的实现左子树,右子树。python代码:class Solution(object): def invertTree(self, root): """ :type root: TreeNode ...原创 2018-03-05 10:01:18 · 130 阅读 · 0 评论 -
leetcode(606):Construct String from Binary Tree
题目要求:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair “()”. And...原创 2018-03-05 11:20:39 · 147 阅读 · 0 评论 -
leetcode(572):Subtree of Another Tree
题目要求: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of thi原创 2018-03-22 22:36:35 · 152 阅读 · 0 评论 -
leetcode(563):Binary Tree Tilt
题目: Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right sub...原创 2018-03-06 14:24:39 · 158 阅读 · 0 评论 -
leetcode(437):Path Sum III
题目要求: You are given a binary tree in which each node contains an integer value.Find the number of paths that sum to a given value.The path does not need to start or end at the root or a leaf, but...原创 2018-03-20 23:08:58 · 173 阅读 · 0 评论 -
leetcode(538):Convert BST to Greater Tree
题目要求: Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. ...原创 2018-03-21 13:21:32 · 145 阅读 · 0 评论 -
leetcode(543):Diameter of Binary Tree
题目要求: Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or原创 2018-03-21 22:43:02 · 250 阅读 · 0 评论 -
leetcode(671):Second Minimum Node In a Binary Tree
题目: Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. If the node has two sub-nodes, then this node’原创 2018-03-08 20:14:46 · 127 阅读 · 0 评论 -
leetcode(107):Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes’ values. (ie, from left to right, level by level from leaf to root).For example: Given binary tree [3,9,20,null,null,1原创 2018-03-14 19:55:12 · 117 阅读 · 0 评论 -
leetcode(237):Delete a node in a Linked list
今天开始刷题,这是准备找工作刷的第一题,之前做了几道string的题,并没有觉得很难,有点不熟悉做题的模式,因为,总觉得前后不连贯,自己的思路受到了限制,现在又要重新进行克服,慢慢来熟悉做题的模式。 首先这个问题,what??真的是,,怀疑自己是不是不具有程序猿的思维啊,什么鬼题呀,是这个样子求解的呀。刚开始做题,真的是读不懂题目,但,熟悉习惯就好了·~不急不急哈·~(精分少女的日常,边怀疑自己原创 2018-01-24 17:01:00 · 162 阅读 · 0 评论 -
leetcode
很久了,做什么都是往笔记本上写,现在重新换个地方记录一下自己的学习经历吧,是个菜鸟,只是菜鸟的思考方式,不知道过段时间找工作的时候,自己是一个什么样的状态,不过,努力啦~~ 今天分析的是leedtcode上面的简单题:20,Valid Parentheses. 给出的是一个字符串,仅仅包括'(', ')', '{', '}', '[', ']',判断给出的字符串是否有效的字符,有效的规则是,字符原创 2017-09-29 20:45:11 · 225 阅读 · 0 评论 -
leetcode(617):Merge Two Binary Trees
题目:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree原创 2018-02-01 17:26:31 · 165 阅读 · 0 评论 -
leetcode(206):Reverse Linked List
题目的要求是:反转一个单链表 题目的线索:可以采用递归或者迭代来实现。 这题分析起来,有一个很顺畅的思路,就是遍历一遍结点,将其存到栈里面,然后依次出栈呀,出一个记录,下一个出栈的结点是上一个出栈结点的后继,这样就可以实现反转,现在关键问题在于:如何来实现栈,使用的python,所以采用list结构来存储结点,实现类似于栈操作的技能。 代码实现(python) (迭代实现)# De原创 2018-01-25 21:20:10 · 173 阅读 · 0 评论 -
leetcode(83):Remove Duplicates from Sorted List
题目: Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 求解的思路,就是让结点的值与后继结点的值进行比较,原创 2018-01-25 22:11:59 · 132 阅读 · 0 评论 -
leetcode(21):Merge Two Sort Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->原创 2018-01-26 15:32:36 · 172 阅读 · 0 评论 -
leetcode(141):Linked List Cycle
题目:Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space?题目分析:判断一个链表中是否存在环,最主要的是判断是否重复遍历的问题。 第一个思路是利用额外的一个数组来进行判断,对于已访问的结点,将其放置在数组中,然后每次再利用数组来原创 2018-01-27 17:34:51 · 160 阅读 · 0 评论 -
leetcode(234):Palindrome Linked List
题目:Given a singly linked list, determine if it is a palindrome.Follow up: Could you do it in O(n) time and O(1) space?分析题目:题目要求的是一个单链表,判断是不是回文,要求用O(n)的时间复杂度,以及O(1)的空间复杂度。第一次超时了·~哎,,利用了一个数组来存储,然后就超时了。。原创 2018-01-28 17:44:34 · 170 阅读 · 0 评论 -
Leetcode(203):Remove Linked List Elements
题目:Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5分析题目:这个题目要求移除具有某个值的链表中的结点。 思考的流程,判断这个节点原创 2018-01-29 15:37:30 · 141 阅读 · 0 评论 -
leetcode(104):Maximunm Depth of Binary Tree
题目: 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 leaf node.For example: Given binary tree [...原创 2018-03-07 17:16:23 · 153 阅读 · 0 评论 -
leetcode(111):Minimum Depth of Binary Tree
题目: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 leaf node.题目分析,求最短的时候的记得分类讨论,对于左子树为None和右子树为N...原创 2018-03-07 19:45:10 · 112 阅读 · 0 评论 -
leetcode(112):Path Sum
题目:Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example: Given the below binary tree and s...原创 2018-03-07 20:08:47 · 118 阅读 · 0 评论 -
leetcode(100):Same Tree
题目:Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.题目分析:...原创 2018-02-18 22:36:56 · 150 阅读 · 0 评论 -
leetcode(101):Symmetric Tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). 对于题目的分析:这个题目要求判断给定的这棵树是不是关于根节点对称。对于根节点而言,首先需要判断根节点是不是为None形式,如果为None形式,则肯定是对称的,然后判断根节点的二个子树的节点情况,使左...原创 2018-02-19 11:04:10 · 171 阅读 · 0 评论 -
leetcode题目:树(一)
1, 二叉搜索树中的是否存在二个数的和为某个数(653)思路:借助外部空间,判断是否有二个数的和为固定的值,避免一直递归来求解。再最后求得那个地方,因为采用中序遍历,所以就是顺序排列,在搜索二个数和为某个值的情况,可以进行一部分优化。class Solution(object): def __init__(self): self._list = [] d...原创 2018-09-20 22:09:32 · 135 阅读 · 0 评论